Commit 76ce3631 by 罗翻

增加选择框,把时间间隔改为15分钟

parent ae7936c9
Showing with 1850 additions and 21 deletions
......@@ -18,12 +18,12 @@ android {
release {
minifyEnabled isReleaseMinify
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "String","BASEURL","\"${BASE_URL}\""
buildConfigField "String", "BASEURL", "\"${BASE_URL}\""
}
debug {
minifyEnabled isDebugMinify
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "String","BASEURL","\"${BASE_URL}\""
buildConfigField "String", "BASEURL", "\"${BASE_URL}\""
}
}
......@@ -61,10 +61,11 @@ dependencies {
//greendao数据库
compile 'org.greenrobot:greendao:3.2.0'
//选择器
compile 'com.contrarywind:Android-PickerView:3.2.7'
// compile 'com.contrarywind:Android-PickerView:3.2.7'
//jsbridge
compile 'com.github.lzyzsd:jsbridge:1.0.4'
compile project(':locationComponent')
compile project(':pickerview')
}
package com.dayu.order.presenter.processorder;
import com.bigkoo.pickerview.OptionsPickerView;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.dayu.base.ui.presenter.BasePresenter;
import com.dayu.common.BaseView;
import com.dayu.widgets.listener.OnCloseListener;
......@@ -40,7 +40,7 @@ public interface ProcessOrderContract {
*/
void getData();
void showPayerDialog(List<String> cardItem, OptionsPickerView.OnOptionsSelectListener listener);
void showPayerDialog(List<String> cardItem, OnOptionsSelectListener listener);
/**
* 当订单不是ka派单时,不可修改.
......
package com.dayu.order.presenter.returnpart;
import com.bigkoo.pickerview.OptionsPickerView;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.dayu.base.ui.presenter.BasePresenter;
import com.dayu.common.BaseView;
......@@ -19,7 +19,7 @@ public interface ReturnPartContract {
* @param cardItem
* @param listener
*/
void showCouriesDialog(List<String> cardItem, OptionsPickerView.OnOptionsSelectListener listener);
void showCouriesDialog(List<String> cardItem, OnOptionsSelectListener listener);
/**
* 关闭输入框.
......
package com.dayu.order.presenter.subcribeTime;
import com.bigkoo.pickerview.TimePickerView;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.dayu.base.ui.presenter.BasePresenter;
import com.dayu.common.BaseView;
......@@ -15,7 +15,7 @@ public interface SubcribeContract {
/**
* 选择时间.
*/
void selectTime(boolean[] type, TimePickerView.OnTimeSelectListener listener);
void selectTime(boolean[] type, OnTimeSelectListener listener);
}
abstract class Presenter extends BasePresenter<View> {
......
......@@ -9,7 +9,9 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import com.bigkoo.pickerview.OptionsPickerView;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.dayu.base.ui.activity.BaseActivity;
import com.dayu.common.Constants;
import com.dayu.order.R;
......@@ -198,9 +200,9 @@ public class ProcessOrderActivity extends BaseActivity<ProcessOrderPresenter, Ac
}
@Override
public void showPayerDialog(List<String> cardItem, OptionsPickerView.OnOptionsSelectListener listener) {
public void showPayerDialog(List<String> cardItem, OnOptionsSelectListener listener) {
//条件选择器
OptionsPickerView pvOptions = new OptionsPickerView.Builder(this, listener)
OptionsPickerView pvOptions = new OptionsPickerBuilder(this, listener)
.setContentTextSize(20)
.setLineSpacingMultiplier(2.0f)
.build();
......
package com.dayu.order.ui.activity;
import com.bigkoo.pickerview.OptionsPickerView;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.dayu.base.ui.activity.BaseActivity;
import com.dayu.order.R;
import com.dayu.order.databinding.ActivityReturnPartBinding;
......@@ -31,9 +33,9 @@ public class ReturnPartActivity extends BaseActivity<ReturnPartPresenter, Activi
}
@Override
public void showCouriesDialog(List<String> cardItem, OptionsPickerView.OnOptionsSelectListener listener) {
public void showCouriesDialog(List<String> cardItem, OnOptionsSelectListener listener) {
//条件选择器
OptionsPickerView pvOptions = new OptionsPickerView.Builder(this, listener)
OptionsPickerView pvOptions = new OptionsPickerBuilder(this, listener)
.setContentTextSize(18)
.setLineSpacingMultiplier(2.0f)
.build();
......
......@@ -4,7 +4,9 @@ import android.content.Context;
import android.graphics.Color;
import android.view.inputmethod.InputMethodManager;
import com.bigkoo.pickerview.TimePickerView;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.dayu.base.ui.activity.BaseActivity;
import com.dayu.order.R;
import com.dayu.order.databinding.ActivitySubscribeTimeBinding;
......@@ -37,20 +39,20 @@ public class SubcribeTimeActivity extends BaseActivity<SubcribeTimePresenter, Ac
}
@Override
public void selectTime(boolean[] type, TimePickerView.OnTimeSelectListener listener) {
public void selectTime(boolean[] type, OnTimeSelectListener listener) {
try {
InputMethodManager imm = (InputMethodManager) mActivity
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mActivity.getCurrentFocus().getWindowToken(), 0);
} catch (NullPointerException e) {
}
TimePickerView pvTime = new TimePickerView.Builder(mActivity, listener)
TimePickerView pvTime = new TimePickerBuilder(mActivity, listener)
.setType(type)//默认全部显示
.setCancelText(getString(R.string.cancle))//取消按钮文字
.setSubmitText(getString(R.string.comfirm))//确认按钮文字
.setContentSize(20)//滚轮文字大小
.setContentTextSize(20)//滚轮文字大小
.setOutSideCancelable(true)//点击屏幕,点在控件外部范围时,是否取消显示
.isCyclic(true)//是否循环滚动
.isCyclic(false)//是否循环滚动
.setTextColorCenter(Color.BLACK)//设置选中项的颜色
.setSubmitColor(Color.BLACK)//确定按钮文字颜色
.setCancelColor(Color.BLACK)//取消按钮文字颜色
......
apply plugin: 'com.android.library'
//apply plugin: 'com.github.dcendents.android-maven'
//apply plugin: 'com.novoda.bintray-release'//添加JCenter插件
android {
compileSdkVersion compile_sdk_version
buildToolsVersion build_tools_version
defaultConfig {
minSdkVersion min_sdk_version
targetSdkVersion target_sdk_version
versionCode version_code
}
buildTypes {
release {
minifyEnabled isReleaseMinify
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
allprojects {
tasks.withType(Javadoc) {//兼容中文字符
options{
encoding "UTF-8"
charSet 'UTF-8'
links "http://docs.oracle.com/javase/7/docs/api"
}
}
}
//publish {
// userOrg = 'contrarywind'//bintray.com 用户名/组织名 user/org name
// groupId = 'com.contrarywind'//JCenter上显示的路径 path
// artifactId = 'Android-PickerView'//项目名称 project name
// publishVersion = '4.1.3'//版本号 version code
// desc = 'this is a pickerview for android'//项目描述 description
// website = 'https://github.com/Bigkoo/Android-PickerView' //项目网址链接 link
//}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(path: ':wheelview')
}
\ No newline at end of file
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/Sai/Documents/software/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
package com.bigkoo.pickerview;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
\ No newline at end of file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bigkoo.pickerview">
</manifest>
package com.bigkoo.pickerview.adapter;
import com.contrarywind.adapter.WheelAdapter;
import java.util.List;
/**
* The simple Array wheel adapter
* @param <T> the element type
*/
public class ArrayWheelAdapter<T> implements WheelAdapter {
// items
private List<T> items;
/**
* Constructor
* @param items the items
*/
public ArrayWheelAdapter(List<T> items) {
this.items = items;
}
@Override
public Object getItem(int index) {
if (index >= 0 && index < items.size()) {
return items.get(index);
}
return "";
}
@Override
public int getItemsCount() {
return items.size();
}
@Override
public int indexOf(Object o){
return items.indexOf(o);
}
}
package com.bigkoo.pickerview.adapter;
import com.contrarywind.adapter.WheelAdapter;
/**
* Numeric Wheel adapter.
*/
public class NumericWheelAdapter implements WheelAdapter {
private int minValue;
private int maxValue;
/**
* Constructor
* @param minValue the wheel min value
* @param maxValue the wheel max value
*/
public NumericWheelAdapter(int minValue, int maxValue) {
this.minValue = minValue;
this.maxValue = maxValue;
}
@Override
public Object getItem(int index) {
if (index >= 0 && index < getItemsCount()) {
int value = minValue + index;
return value;
}
return 0;
}
@Override
public int getItemsCount() {
return maxValue - minValue + 1;
}
@Override
public int indexOf(Object o){
try {
return (int)o - minValue;
} catch (Exception e) {
return -1;
}
}
}
package com.bigkoo.pickerview.builder;
import android.content.Context;
import android.graphics.Typeface;
import android.view.ViewGroup;
import com.bigkoo.pickerview.configure.PickerOptions;
import com.bigkoo.pickerview.listener.CustomListener;
import com.bigkoo.pickerview.listener.OnOptionsSelectChangeListener;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.contrarywind.view.WheelView;
/**
* Created by xiaosongzeem on 2018/3/20.
*/
public class OptionsPickerBuilder {
//配置类
private PickerOptions mPickerOptions;
//Required
public OptionsPickerBuilder(Context context, OnOptionsSelectListener listener) {
mPickerOptions = new PickerOptions(PickerOptions.TYPE_PICKER_OPTIONS);
mPickerOptions.context = context;
mPickerOptions.optionsSelectListener = listener;
}
//Option
public OptionsPickerBuilder setSubmitText(String textContentConfirm) {
mPickerOptions.textContentConfirm = textContentConfirm;
return this;
}
public OptionsPickerBuilder setCancelText(String textContentCancel) {
mPickerOptions.textContentCancel = textContentCancel;
return this;
}
public OptionsPickerBuilder setTitleText(String textContentTitle) {
mPickerOptions.textContentTitle = textContentTitle;
return this;
}
public OptionsPickerBuilder isDialog(boolean isDialog) {
mPickerOptions.isDialog = isDialog;
return this;
}
public OptionsPickerBuilder setSubmitColor(int textColorConfirm) {
mPickerOptions.textColorConfirm = textColorConfirm;
return this;
}
public OptionsPickerBuilder setCancelColor(int textColorCancel) {
mPickerOptions.textColorCancel = textColorCancel;
return this;
}
/**
* 显示时的外部背景色颜色,默认是灰色
*
* @param backgroundId color resId.
* @return
*/
public OptionsPickerBuilder setBackgroundId(int backgroundId) {
mPickerOptions.backgroundId = backgroundId;
return this;
}
/**
* ViewGroup 类型
* 设置PickerView的显示容器
*
* @param decorView Parent View.
* @return
*/
public OptionsPickerBuilder setDecorView(ViewGroup decorView) {
mPickerOptions.decorView = decorView;
return this;
}
public OptionsPickerBuilder setLayoutRes(int res, CustomListener listener) {
mPickerOptions.layoutRes = res;
mPickerOptions.customListener = listener;
return this;
}
public OptionsPickerBuilder setBgColor(int bgColorWheel) {
mPickerOptions.bgColorWheel = bgColorWheel;
return this;
}
public OptionsPickerBuilder setTitleBgColor(int bgColorTitle) {
mPickerOptions.bgColorTitle = bgColorTitle;
return this;
}
public OptionsPickerBuilder setTitleColor(int textColorTitle) {
mPickerOptions.textColorTitle = textColorTitle;
return this;
}
public OptionsPickerBuilder setSubCalSize(int textSizeSubmitCancel) {
mPickerOptions.textSizeSubmitCancel = textSizeSubmitCancel;
return this;
}
public OptionsPickerBuilder setTitleSize(int textSizeTitle) {
mPickerOptions.textSizeTitle = textSizeTitle;
return this;
}
public OptionsPickerBuilder setContentTextSize(int textSizeContent) {
mPickerOptions.textSizeContent = textSizeContent;
return this;
}
public OptionsPickerBuilder setOutSideCancelable(boolean cancelable) {
mPickerOptions.cancelable = cancelable;
return this;
}
public OptionsPickerBuilder setLabels(String label1, String label2, String label3) {
mPickerOptions.label1 = label1;
mPickerOptions.label2 = label2;
mPickerOptions.label3 = label3;
return this;
}
/**
* 设置Item 的间距倍数,用于控制 Item 高度间隔
*
* @param lineSpacingMultiplier 浮点型,1.0-4.0f 之间有效,超过则取极值。
*/
public OptionsPickerBuilder setLineSpacingMultiplier(float lineSpacingMultiplier) {
mPickerOptions.lineSpacingMultiplier = lineSpacingMultiplier;
return this;
}
/**
* Set item divider line type color.
*
* @param dividerColor color resId.
*/
public OptionsPickerBuilder setDividerColor(int dividerColor) {
mPickerOptions.dividerColor = dividerColor;
return this;
}
/**
* Set item divider line type.
*
* @param dividerType enum Type {@link WheelView.DividerType}
*/
public OptionsPickerBuilder setDividerType(WheelView.DividerType dividerType) {
mPickerOptions.dividerType = dividerType;
return this;
}
/**
* Set the textColor of selected item.
*
* @param textColorCenter color res.
*/
public OptionsPickerBuilder setTextColorCenter(int textColorCenter) {
mPickerOptions.textColorCenter = textColorCenter;
return this;
}
/**
* Set the textColor of outside item.
*
* @param textColorOut color resId.
*/
public OptionsPickerBuilder setTextColorOut(int textColorOut) {
mPickerOptions.textColorOut = textColorOut;
return this;
}
public OptionsPickerBuilder setTypeface(Typeface font) {
mPickerOptions.font = font;
return this;
}
public OptionsPickerBuilder setCyclic(boolean cyclic1, boolean cyclic2, boolean cyclic3) {
mPickerOptions.cyclic1 = cyclic1;
mPickerOptions.cyclic2 = cyclic2;
mPickerOptions.cyclic3 = cyclic3;
return this;
}
public OptionsPickerBuilder setSelectOptions(int option1) {
mPickerOptions.option1 = option1;
return this;
}
public OptionsPickerBuilder setSelectOptions(int option1, int option2) {
mPickerOptions.option1 = option1;
mPickerOptions.option2 = option2;
return this;
}
public OptionsPickerBuilder setSelectOptions(int option1, int option2, int option3) {
mPickerOptions.option1 = option1;
mPickerOptions.option2 = option2;
mPickerOptions.option3 = option3;
return this;
}
public OptionsPickerBuilder setTextXOffset(int xoffset_one, int xoffset_two, int xoffset_three) {
mPickerOptions.x_offset_one = xoffset_one;
mPickerOptions.x_offset_two = xoffset_two;
mPickerOptions.x_offset_three = xoffset_three;
return this;
}
public OptionsPickerBuilder isCenterLabel(boolean isCenterLabel) {
mPickerOptions.isCenterLabel = isCenterLabel;
return this;
}
/**
* 切换选项时,是否还原第一项
*
* @param isRestoreItem true:还原; false: 保持上一个选项
* @return TimePickerBuilder
*/
public OptionsPickerBuilder isRestoreItem(boolean isRestoreItem) {
mPickerOptions.isRestoreItem = isRestoreItem;
return this;
}
/**
* @param listener 切换item项滚动停止时,实时回调监听。
* @return
*/
public OptionsPickerBuilder setOptionsSelectChangeListener(OnOptionsSelectChangeListener listener) {
mPickerOptions.optionsSelectChangeListener = listener;
return this;
}
public <T> OptionsPickerView<T> build() {
return new OptionsPickerView<>(mPickerOptions);
}
}
package com.bigkoo.pickerview.builder;
import android.content.Context;
import android.view.ViewGroup;
import com.bigkoo.pickerview.configure.PickerOptions;
import com.bigkoo.pickerview.listener.OnTimeSelectChangeListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.bigkoo.pickerview.listener.CustomListener;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.contrarywind.view.WheelView;
import java.util.Calendar;
/**
* Created by xiaosongzeem on 2018/3/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;
}
//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 type 布尔型数组,长度需要设置为6。
* @return TimePickerBuilder
*/
public TimePickerBuilder setType(boolean[] type) {
mPickerOptions.type = type;
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);
}
}
package com.bigkoo.pickerview.configure;
import android.content.Context;
import android.graphics.Typeface;
import android.view.Gravity;
import android.view.ViewGroup;
import com.bigkoo.pickerview.listener.OnOptionsSelectChangeListener;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.R;
import com.bigkoo.pickerview.listener.CustomListener;
import com.bigkoo.pickerview.listener.OnTimeSelectChangeListener;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.contrarywind.view.WheelView;
import java.util.Calendar;
/**
* 配置类
* Created by xiaosongzeem on 2018/3/8.
*/
public class PickerOptions {
//常量
private static final int PICKER_VIEW_BTN_COLOR_NORMAL = 0xFF057dff;
private static final int PICKER_VIEW_BG_COLOR_TITLE = 0xFFf5f5f5;
private static final int PICKER_VIEW_COLOR_TITLE = 0xFF000000;
private static final int PICKER_VIEW_BG_COLOR_DEFAULT = 0xFFFFFFFF;
public static final int TYPE_PICKER_OPTIONS = 1;
public static final int TYPE_PICKER_TIME = 2;
public OnOptionsSelectListener optionsSelectListener;
public OnTimeSelectListener timeSelectListener;
public OnTimeSelectChangeListener timeSelectChangeListener;
public OnOptionsSelectChangeListener optionsSelectChangeListener;
public CustomListener customListener;
//options picker
public String label1, label2, label3;//单位字符
public int option1, option2, option3;//默认选中项
public int x_offset_one, x_offset_two, x_offset_three;//x轴偏移量
public boolean cyclic1 = false;//是否循环,默认否
public boolean cyclic2 = false;
public boolean cyclic3 = false;
public boolean isRestoreItem = false; //切换时,还原第一项
//time picker
public boolean[] type = new boolean[]{true, true, true, false, false, false};//显示类型,默认显示: 年月日
public Calendar date;//当前选中时间
public Calendar startDate;//开始时间
public Calendar endDate;//终止时间
public int startYear;//开始年份
public int endYear;//结尾年份
public boolean cyclic = false;//是否循环
public boolean isLunarCalendar = false;//是否显示农历
public String label_year, label_month, label_day, label_hours, label_minutes, label_seconds;//单位
public int x_offset_year, x_offset_month, x_offset_day, x_offset_hours, x_offset_minutes, x_offset_seconds;//单位
public PickerOptions(int buildType) {
if (buildType == TYPE_PICKER_OPTIONS) {
layoutRes = R.layout.pickerview_options;
} else {
layoutRes = R.layout.pickerview_time;
}
}
//******* 公有字段 ******//
public int layoutRes;
public ViewGroup decorView;
public int textGravity = Gravity.CENTER;
public Context context;
public String textContentConfirm;//确定按钮文字
public String textContentCancel;//取消按钮文字
public String textContentTitle;//标题文字
public int textColorConfirm = PICKER_VIEW_BTN_COLOR_NORMAL;//确定按钮颜色
public int textColorCancel = PICKER_VIEW_BTN_COLOR_NORMAL;//取消按钮颜色
public int textColorTitle = PICKER_VIEW_COLOR_TITLE;//标题颜色
public int bgColorWheel = PICKER_VIEW_BG_COLOR_DEFAULT;//滚轮背景颜色
public int bgColorTitle = PICKER_VIEW_BG_COLOR_TITLE;//标题背景颜色
public int textSizeSubmitCancel = 17;//确定取消按钮大小
public int textSizeTitle = 18;//标题文字大小
public int textSizeContent = 18;//内容文字大小
public int textColorOut = 0xFFa8a8a8; //分割线以外的文字颜色
public int textColorCenter = 0xFF2a2a2a; //分割线之间的文字颜色
public int dividerColor = 0xFFd5d5d5; //分割线的颜色
public int backgroundId = -1; //显示时的外部背景色颜色,默认是灰色
public float lineSpacingMultiplier = 1.6f; // 条目间距倍数 默认1.6
public boolean isDialog;//是否是对话框模式
public boolean cancelable = true;//是否能取消
public boolean isCenterLabel = false;//是否只显示中间的label,默认每个item都显示
public Typeface font = Typeface.MONOSPACE;//字体样式
public WheelView.DividerType dividerType = WheelView.DividerType.FILL;//分隔线类型
}
package com.bigkoo.pickerview.listener;
import android.view.View;
/**
* Created by KyuYi on 2017/3/2.
* E-Mail:kyu_yi@sina.com
* 功能:
*/
public interface CustomListener {
void customLayout(View v);
}
package com.bigkoo.pickerview.listener;
/**
* Created by zengsong on 2018/3/21.
*/
public interface ISelectTimeCallback {
public void onTimeSelectChanged();
}
package com.bigkoo.pickerview.listener;
/**
* Created by Sai on 15/8/9.
*/
public interface OnDismissListener {
public void onDismiss(Object o);
}
package com.bigkoo.pickerview.listener;
/**
* Created by xiaosong on 2018/3/20.
*/
public interface OnOptionsSelectChangeListener {
void onOptionsSelectChanged(int options1, int options2, int options3);
}
package com.bigkoo.pickerview.listener;
import android.view.View;
/**
* Created by xiaosong on 2018/3/20.
*/
public interface OnOptionsSelectListener {
void onOptionsSelect(int options1, int options2, int options3, View v);
}
package com.bigkoo.pickerview.listener;
import java.util.Date;
/**
* Created by xiaosong on 2018/3/20.
*/
public interface OnTimeSelectChangeListener {
void onTimeSelectChanged(Date date);
}
package com.bigkoo.pickerview.listener;
import android.view.View;
import java.util.Date;
/**
* Created by xiaosong on 2018/3/20.
*/
public interface OnTimeSelectListener {
void onTimeSelect(Date date, View v);
}
package com.bigkoo.pickerview.utils;
import android.view.Gravity;
import com.bigkoo.pickerview.R;
/**
* Created by Sai on 15/8/9.
*/
public class PickerViewAnimateUtil {
private static final int INVALID = -1;
/**
* Get default animation resource when not defined by the user
*
* @param gravity the animGravity of the dialog
* @param isInAnimation determine if is in or out animation. true when is is
* @return the id of the animation resource
*/
public static int getAnimationResource(int gravity, boolean isInAnimation) {
switch (gravity) {
case Gravity.BOTTOM:
return isInAnimation ? R.anim.pickerview_slide_in_bottom : R.anim.pickerview_slide_out_bottom;
}
return INVALID;
}
}
package com.bigkoo.pickerview.view;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.bigkoo.pickerview.R;
import com.bigkoo.pickerview.configure.PickerOptions;
import java.util.List;
/**
* 条件选择器
* Created by Sai on 15/11/22.
*/
public class OptionsPickerView<T> extends BasePickerView implements View.OnClickListener {
private WheelOptions wheelOptions;
private static final String TAG_SUBMIT = "submit";
private static final String TAG_CANCEL = "cancel";
public OptionsPickerView(PickerOptions pickerOptions) {
super(pickerOptions.context);
mPickerOptions = pickerOptions;
initView(pickerOptions.context);
}
private void initView(Context context) {
setDialogOutSideCancelable();
initViews();
initAnim();
initEvents();
if (mPickerOptions.customListener == null) {
LayoutInflater.from(context).inflate(mPickerOptions.layoutRes, contentContainer);
//顶部标题
TextView tvTitle = (TextView) findViewById(R.id.tvTitle);
RelativeLayout rv_top_bar = (RelativeLayout) findViewById(R.id.rv_topbar);
//确定和取消按钮
Button btnSubmit = (Button) findViewById(R.id.btnSubmit);
Button btnCancel = (Button) findViewById(R.id.btnCancel);
btnSubmit.setTag(TAG_SUBMIT);
btnCancel.setTag(TAG_CANCEL);
btnSubmit.setOnClickListener(this);
btnCancel.setOnClickListener(this);
//设置文字
btnSubmit.setText(TextUtils.isEmpty(mPickerOptions.textContentConfirm) ? context.getResources().getString(R.string.pickerview_submit) : mPickerOptions.textContentConfirm);
btnCancel.setText(TextUtils.isEmpty(mPickerOptions.textContentCancel) ? context.getResources().getString(R.string.pickerview_cancel) : mPickerOptions.textContentCancel);
tvTitle.setText(TextUtils.isEmpty(mPickerOptions.textContentTitle) ? "" : mPickerOptions.textContentTitle);//默认为空
//设置color
btnSubmit.setTextColor(mPickerOptions.textColorConfirm);
btnCancel.setTextColor(mPickerOptions.textColorCancel);
tvTitle.setTextColor(mPickerOptions.textColorTitle);
rv_top_bar.setBackgroundColor(mPickerOptions.bgColorTitle);
//设置文字大小
btnSubmit.setTextSize(mPickerOptions.textSizeSubmitCancel);
btnCancel.setTextSize(mPickerOptions.textSizeSubmitCancel);
tvTitle.setTextSize(mPickerOptions.textSizeTitle);
} else {
mPickerOptions.customListener.customLayout(LayoutInflater.from(context).inflate(mPickerOptions.layoutRes, contentContainer));
}
// ----滚轮布局
final LinearLayout optionsPicker = (LinearLayout) findViewById(R.id.optionspicker);
optionsPicker.setBackgroundColor(mPickerOptions.bgColorWheel);
wheelOptions = new WheelOptions(optionsPicker, mPickerOptions.isRestoreItem);
if (mPickerOptions.optionsSelectChangeListener != null) {
wheelOptions.setOptionsSelectChangeListener(mPickerOptions.optionsSelectChangeListener);
}
wheelOptions.setTextContentSize(mPickerOptions.textSizeContent);
wheelOptions.setLabels(mPickerOptions.label1, mPickerOptions.label2, mPickerOptions.label3);
wheelOptions.setTextXOffset(mPickerOptions.x_offset_one, mPickerOptions.x_offset_two, mPickerOptions.x_offset_three);
wheelOptions.setCyclic(mPickerOptions.cyclic1, mPickerOptions.cyclic2, mPickerOptions.cyclic3);
wheelOptions.setTypeface(mPickerOptions.font);
setOutSideCancelable(mPickerOptions.cancelable);
wheelOptions.setDividerColor(mPickerOptions.dividerColor);
wheelOptions.setDividerType(mPickerOptions.dividerType);
wheelOptions.setLineSpacingMultiplier(mPickerOptions.lineSpacingMultiplier);
wheelOptions.setTextColorOut(mPickerOptions.textColorOut);
wheelOptions.setTextColorCenter(mPickerOptions.textColorCenter);
wheelOptions.isCenterLabel(mPickerOptions.isCenterLabel);
}
/**
* 动态设置标题
*
* @param text 标题文本内容
*/
public void setTitleText(String text) {
TextView tvTitle = (TextView) findViewById(R.id.tvTitle);
if (tvTitle != null) {
tvTitle.setText(text);
}
}
/**
* 设置默认选中项
*
* @param option1
*/
public void setSelectOptions(int option1) {
mPickerOptions.option1 = option1;
reSetCurrentItems();
}
public void setSelectOptions(int option1, int option2) {
mPickerOptions.option1 = option1;
mPickerOptions.option2 = option2;
reSetCurrentItems();
}
public void setSelectOptions(int option1, int option2, int option3) {
mPickerOptions.option1 = option1;
mPickerOptions.option2 = option2;
mPickerOptions.option3 = option3;
reSetCurrentItems();
}
private void reSetCurrentItems() {
if (wheelOptions != null) {
wheelOptions.setCurrentItems(mPickerOptions.option1, mPickerOptions.option2, mPickerOptions.option3);
}
}
public void setPicker(List<T> optionsItems) {
this.setPicker(optionsItems, null, null);
}
public void setPicker(List<T> options1Items, List<List<T>> options2Items) {
this.setPicker(options1Items, options2Items, null);
}
public void setPicker(List<T> options1Items,
List<List<T>> options2Items,
List<List<List<T>>> options3Items) {
wheelOptions.setPicker(options1Items, options2Items, options3Items);
reSetCurrentItems();
}
//不联动情况下调用
public void setNPicker(List<T> options1Items,
List<T> options2Items,
List<T> options3Items) {
wheelOptions.setLinkage(false);
wheelOptions.setNPicker(options1Items, options2Items, options3Items);
reSetCurrentItems();
}
@Override
public void onClick(View v) {
String tag = (String) v.getTag();
if (tag.equals(TAG_SUBMIT)) {
returnData();
}
dismiss();
}
//抽离接口回调的方法
public void returnData() {
if (mPickerOptions.optionsSelectListener != null) {
int[] optionsCurrentItems = wheelOptions.getCurrentItems();
mPickerOptions.optionsSelectListener.onOptionsSelect(optionsCurrentItems[0], optionsCurrentItems[1], optionsCurrentItems[2], clickView);
}
}
@Override
public boolean isDialog() {
return mPickerOptions.isDialog;
}
}
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:duration="@integer/animation_default_duration"
android:fromAlpha="0.0"
android:toAlpha="1.0" />
<scale
android:duration="@integer/animation_default_duration"
android:fromXScale="0.0"
android:toXScale="1.0"
android:fromYScale="0.0"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"/>
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:duration="@integer/animation_default_duration"
android:fromAlpha="1.0"
android:toAlpha="0.3" />
<scale
android:duration="@integer/animation_default_duration"
android:fromXScale="1.0"
android:toXScale="0.0"
android:fromYScale="1.0"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"/>
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="@integer/animation_default_duration"
android:fromXDelta="0%"
android:toXDelta="0%"
android:fromYDelta="100%"
android:toYDelta="0%"/>
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="@integer/animation_default_duration"
android:fromXDelta="0%"
android:toXDelta="0%"
android:fromYDelta="0%"
android:toYDelta="100%"/>
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="@color/pickerview_timebtn_pre" />
<item android:color="@color/pickerview_timebtn_nor" />
</selector>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rv_topbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/pickerview_bg_topbar">
<Button
android:id="@+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:gravity="left|center_vertical"
android:paddingLeft="@dimen/pickerview_topbar_padding"
android:text="@string/pickerview_cancel"
android:textColor="@drawable/selector_pickerview_btn"
android:textSize="@dimen/pickerview_topbar_btn_textsize" />
<TextView
android:id="@+id/tvTitle"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/btnSubmit"
android:layout_toRightOf="@+id/btnCancel"
android:textColor="@color/pickerview_topbar_title"
android:textSize="@dimen/pickerview_topbar_title_textsize" />
<Button
android:id="@id/btnSubmit"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:background="@android:color/transparent"
android:gravity="right|center_vertical"
android:paddingRight="@dimen/pickerview_topbar_padding"
android:text="@string/pickerview_submit"
android:textColor="@drawable/selector_pickerview_btn"
android:textSize="@dimen/pickerview_topbar_btn_textsize" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:id="@+id/outmost_container"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:background="@color/pickerview_bgColor_overlay">
<FrameLayout
android:id="@+id/content_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</FrameLayout>
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
layout="@layout/include_pickerview_topbar"
android:layout_width="match_parent"
android:layout_height="@dimen/pickerview_topbar_height" />
<LinearLayout
android:id="@+id/optionspicker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="horizontal">
<com.contrarywind.view.WheelView
android:id="@+id/options1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<com.contrarywind.view.WheelView
android:id="@+id/options2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<com.contrarywind.view.WheelView
android:id="@+id/options3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
layout="@layout/include_pickerview_topbar"
android:layout_width="match_parent"
android:layout_height="@dimen/pickerview_topbar_height" />
<LinearLayout
android:id="@+id/timepicker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="horizontal">
<com.contrarywind.view.WheelView
android:id="@+id/year"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.96" />
<com.contrarywind.view.WheelView
android:id="@+id/month"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<com.contrarywind.view.WheelView
android:id="@+id/day"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<com.contrarywind.view.WheelView
android:id="@+id/hour"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<com.contrarywind.view.WheelView
android:id="@+id/min"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<com.contrarywind.view.WheelView
android:id="@+id/second"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
<resources>
<string name="pickerview_cancel">Cancel</string>
<string name="pickerview_submit">Confirm</string>
<string name="pickerview_year"> </string>
<string name="pickerview_month"> </string>
<string name="pickerview_day"> </string>
<string name="pickerview_hours"> </string>
<string name="pickerview_minutes"> </string>
<string name="pickerview_seconds"> </string>
</resources>
<resources>
<!-- 顶部按钮栏高度 -->
<dimen name="pickerview_topbar_height">44dp</dimen>
<!-- 顶部按钮padding -->
<dimen name="pickerview_topbar_padding">20dp</dimen>
<!-- 顶部按钮文字大小 -->
<dimen name="pickerview_topbar_btn_textsize">17sp</dimen>
<dimen name="pickerview_topbar_title_textsize">18sp</dimen>
<!-- 选项文字大小 -->
<dimen name="pickerview_textsize">20sp</dimen>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="animation_default_duration">300</integer>
</resources>
\ No newline at end of file
<resources>
<string name="pickerview_cancel">取消</string>
<string name="pickerview_submit">确定</string>
<string name="pickerview_year"></string>
<string name="pickerview_month"></string>
<string name="pickerview_day"></string>
<string name="pickerview_hours"></string>
<string name="pickerview_minutes"></string>
<string name="pickerview_seconds"></string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="custom_dialog2" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<!-- Dialog的windowFrame框为无 -->
<item name="android:windowIsFloating">true</item>
<!-- 是否漂现在activity上 -->
<item name="android:windowIsTranslucent">true</item>
<!-- 是否半透明 -->
<item name="android:windowNoTitle">true</item>
<item name="android:background">@null</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<!-- 去除黑色边框的关键设置项 -->
<item name="android:backgroundDimEnabled">true</item>
<!-- 屏幕背景是否变暗 -->
<item name="android:backgroundDimAmount">0.3</item>
</style>
<style name="picker_view_scale_anim" mce_bogus="1" parent="android:Animation">
<item name="android:windowEnterAnimation">@anim/pickerview_dialog_scale_in</item>
<item name="android:windowExitAnimation">@anim/pickerview_dialog_scale_out</item>
</style>
<style name="picker_view_slide_anim" mce_bogus="1" parent="android:Animation">
<item name="android:windowEnterAnimation">@anim/pickerview_slide_in_bottom</item>
<item name="android:windowExitAnimation">@anim/pickerview_slide_out_bottom</item>
</style>
</resources>
......@@ -4,4 +4,6 @@ include ':app',
':messageCenter',
':userCenter',
':orderCenter',
':locationComponent'
':locationComponent',
':pickerview',
':wheelview'
apply plugin: 'com.android.library'
//apply plugin: 'com.github.dcendents.android-maven'
//apply plugin: 'com.novoda.bintray-release'//添加插件
android {
compileSdkVersion compile_sdk_version
buildToolsVersion build_tools_version
defaultConfig {
minSdkVersion min_sdk_version
targetSdkVersion target_sdk_version
versionCode version_code
}
buildTypes {
release {
minifyEnabled isReleaseMinify
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
allprojects {
tasks.withType(Javadoc) {//兼容中文字符
options {
encoding "UTF-8"
charSet 'UTF-8'
links "http://docs.oracle.com/javase/7/docs/api"
}
}
}
//publish {
// userOrg = 'contrarywind'//bintray.com 用户名/组织名 user/org name
// groupId = 'com.contrarywind'//JCenter上显示的路径 path
// artifactId = 'wheelview'//项目名称 project name
// publishVersion = '4.0.5'//版本号 version code
// desc = 'this is a wheelview for android'//项目描述 description
// website = 'https://github.com/Bigkoo/Android-PickerView' //项目网址链接 link
//}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
}
\ No newline at end of file
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Users\song\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
package test.wheelview;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("test.wheelview.test", appContext.getPackageName());
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.contrarywind.view">
<application android:allowBackup="true" android:label="@string/app_name"
android:supportsRtl="true">
</application>
</manifest>
package com.contrarywind.adapter;
public interface WheelAdapter<T> {
/**
* Gets items count
* @return the count of wheel items
*/
int getItemsCount();
/**
* Gets a wheel item by index.
* @param index the item index
* @return the wheel item text or null
*/
T getItem(int index);
/**
* Gets maximum item length. It is used to determine the wheel width.
* If -1 is returned there will be used the default wheel width.
* @param o the item object
* @return the maximum item length or -1
*/
int indexOf(T o);
}
package com.contrarywind.interfaces;
/**
* Created by Sai on 2016/7/13.
*/
public interface IPickerViewData {
String getPickerViewText();
}
package com.contrarywind.listener;
import android.view.MotionEvent;
import com.contrarywind.view.WheelView;
/**
* 手势监听
*/
public final class LoopViewGestureListener extends android.view.GestureDetector.SimpleOnGestureListener {
private final WheelView wheelView;
public LoopViewGestureListener(WheelView wheelView) {
this.wheelView = wheelView;
}
@Override
public final boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
wheelView.scrollBy(velocityY);
return true;
}
}
package com.contrarywind.listener;
public interface OnItemSelectedListener {
void onItemSelected(int index);
}
package com.contrarywind.timer;
import com.contrarywind.view.WheelView;
import java.util.TimerTask;
/**
* 滚动惯性的实现
*
* @author 小嵩
* date: 2017-12-23 23:20:44
*/
public final class InertiaTimerTask extends TimerTask {
private float mCurrentVelocityY; //当前滑动速度
private final float mFirstVelocityY;//手指离开屏幕时的初始速度
private final WheelView mWheelView;
/**
* @param wheelView 滚轮对象
* @param velocityY Y轴滑行速度
*/
public InertiaTimerTask(WheelView wheelView, float velocityY) {
super();
this.mWheelView = wheelView;
this.mFirstVelocityY = velocityY;
mCurrentVelocityY = Integer.MAX_VALUE;
}
@Override
public final void run() {
//防止闪动,对速度做一个限制。
if (mCurrentVelocityY == Integer.MAX_VALUE) {
if (Math.abs(mFirstVelocityY) > 2000F) {
mCurrentVelocityY = mFirstVelocityY > 0 ? 2000F : -2000F;
} else {
mCurrentVelocityY = mFirstVelocityY;
}
}
//发送handler消息 处理平顺停止滚动逻辑
if (Math.abs(mCurrentVelocityY) >= 0.0F && Math.abs(mCurrentVelocityY) <= 20F) {
mWheelView.cancelFuture();
mWheelView.getHandler().sendEmptyMessage(MessageHandler.WHAT_SMOOTH_SCROLL);
return;
}
int dy = (int) (mCurrentVelocityY / 100F);
mWheelView.setTotalScrollY(mWheelView.getTotalScrollY() - dy);
if (!mWheelView.isLoop()) {
float itemHeight = mWheelView.getItemHeight();
float top = (-mWheelView.getInitPosition()) * itemHeight;
float bottom = (mWheelView.getItemsCount() - 1 - mWheelView.getInitPosition()) * itemHeight;
if (mWheelView.getTotalScrollY() - itemHeight * 0.25 < top) {
top = mWheelView.getTotalScrollY() + dy;
} else if (mWheelView.getTotalScrollY() + itemHeight * 0.25 > bottom) {
bottom = mWheelView.getTotalScrollY() + dy;
}
if (mWheelView.getTotalScrollY() <= top) {
mCurrentVelocityY = 40F;
mWheelView.setTotalScrollY((int) top);
} else if (mWheelView.getTotalScrollY() >= bottom) {
mWheelView.setTotalScrollY((int) bottom);
mCurrentVelocityY = -40F;
}
}
if (mCurrentVelocityY < 0.0F) {
mCurrentVelocityY = mCurrentVelocityY + 20F;
} else {
mCurrentVelocityY = mCurrentVelocityY - 20F;
}
//刷新UI
mWheelView.getHandler().sendEmptyMessage(MessageHandler.WHAT_INVALIDATE_LOOP_VIEW);
}
}
package com.contrarywind.timer;
import android.os.Handler;
import android.os.Message;
import com.contrarywind.view.WheelView;
/**
* Handler 消息类
*
* @author 小嵩
* date: 2017-12-23 23:20:44
*/
public final class MessageHandler extends Handler {
public static final int WHAT_INVALIDATE_LOOP_VIEW = 1000;
public static final int WHAT_SMOOTH_SCROLL = 2000;
public static final int WHAT_ITEM_SELECTED = 3000;
private final WheelView wheelView;
public MessageHandler(WheelView wheelView) {
this.wheelView = wheelView;
}
@Override
public final void handleMessage(Message msg) {
switch (msg.what) {
case WHAT_INVALIDATE_LOOP_VIEW:
wheelView.invalidate();
break;
case WHAT_SMOOTH_SCROLL:
wheelView.smoothScroll(WheelView.ACTION.FLING);
break;
case WHAT_ITEM_SELECTED:
wheelView.onItemSelected();
break;
}
}
}
package com.contrarywind.timer;
import com.contrarywind.view.WheelView;
import java.util.TimerTask;
/**
* 平滑滚动的实现
*
* @author 小嵩
*/
public final class SmoothScrollTimerTask extends TimerTask {
private int realTotalOffset;
private int realOffset;
private int offset;
private final WheelView wheelView;
public SmoothScrollTimerTask(WheelView wheelView, int offset) {
this.wheelView = wheelView;
this.offset = offset;
realTotalOffset = Integer.MAX_VALUE;
realOffset = 0;
}
@Override
public final void run() {
if (realTotalOffset == Integer.MAX_VALUE) {
realTotalOffset = offset;
}
//把要滚动的范围细分成10小份,按10小份单位来重绘
realOffset = (int) ((float) realTotalOffset * 0.1F);
if (realOffset == 0) {
if (realTotalOffset < 0) {
realOffset = -1;
} else {
realOffset = 1;
}
}
if (Math.abs(realTotalOffset) <= 1) {
wheelView.cancelFuture();
wheelView.getHandler().sendEmptyMessage(MessageHandler.WHAT_ITEM_SELECTED);
} else {
wheelView.setTotalScrollY(wheelView.getTotalScrollY() + realOffset);
//这里如果不是循环模式,则点击空白位置需要回滚,不然就会出现选到-1 item的 情况
if (!wheelView.isLoop()) {
float itemHeight = wheelView.getItemHeight();
float top = (float) (-wheelView.getInitPosition()) * itemHeight;
float bottom = (float) (wheelView.getItemsCount() - 1 - wheelView.getInitPosition()) * itemHeight;
if (wheelView.getTotalScrollY() <= top || wheelView.getTotalScrollY() >= bottom) {
wheelView.setTotalScrollY(wheelView.getTotalScrollY() - realOffset);
wheelView.cancelFuture();
wheelView.getHandler().sendEmptyMessage(MessageHandler.WHAT_ITEM_SELECTED);
return;
}
}
wheelView.getHandler().sendEmptyMessage(MessageHandler.WHAT_INVALIDATE_LOOP_VIEW);
realTotalOffset = realTotalOffset - realOffset;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="pickerview">
<attr name="wheelview_gravity">
<enum name="center" value="17"/>
<enum name="left" value="3"/>
<enum name="right" value="5"/>
</attr>
<attr name="wheelview_textSize" format="dimension"/>
<attr name="wheelview_textColorOut" format="color"/>
<attr name="wheelview_textColorCenter" format="color"/>
<attr name="wheelview_dividerColor" format="color"/>
<attr name="wheelview_lineSpacingMultiplier" format="float"/>
</declare-styleable>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="pickerview_timebtn_nor">#057dff</color>
<color name="pickerview_timebtn_pre">#c2daf5</color>
<color name="pickerview_bg_topbar">#f5f5f5</color>
<color name="pickerview_topbar_title">#000000</color>
<color name="pickerview_wheelview_textcolor_out">#a8a8a8</color>
<color name="pickerview_wheelview_textcolor_center">#2a2a2a</color>
<color name="pickerview_wheelview_textcolor_divider">#d5d5d5</color>
<color name="pickerview_bgColor_overlay">#60000000</color>
<color name="pickerview_bgColor_default">#FFFFFFFF</color>
</resources>
<resources>
<!-- 顶部按钮栏高度 -->
<dimen name="pickerview_topbar_height">44dp</dimen>
<!-- 顶部按钮padding -->
<dimen name="pickerview_topbar_padding">20dp</dimen>
<!-- 顶部按钮文字大小 -->
<dimen name="pickerview_topbar_btn_textsize">17sp</dimen>
<dimen name="pickerview_topbar_title_textsize">18sp</dimen>
<!-- 选项文字大小 -->
<dimen name="pickerview_textsize">20sp</dimen>
</resources>
<resources>
<string name="app_name">wheelview</string>
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment