From 633e03b2393b50c5857044845c7872a75e00ed43 Mon Sep 17 00:00:00 2001 From: liyujiang Date: Fri, 16 Dec 2016 02:04:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=80=E6=9C=89=E9=80=89=E6=8B=A9=E5=99=A8?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=BB=91=E5=8A=A8=E5=AE=9E=E6=97=B6=E7=9B=91?= =?UTF-8?q?=E5=90=AC=E3=80=81=E6=94=AF=E6=8C=81=E5=86=85=E5=B5=8C=E5=88=B0?= =?UTF-8?q?=E5=85=B6=E4=BB=96=E8=A7=86=E5=9B=BE=E5=AE=B9=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ChangeLog.md | 12 +++- README.md | 20 +++--- app/src/main/AndroidManifest.xml | 13 ++-- .../qqtheme/androidpicker/MainActivity.java | 58 ++++++++++++------ .../qqtheme/androidpicker/NestActivity.java | 56 +++++++++++++++++ app/src/main/res/layout/activity_main.xml | 6 ++ app/src/main/res/layout/activity_nest.xml | 33 ++++++++++ gradle.properties | 4 +- .../qqtheme/framework/picker/ColorPicker.java | 1 + .../qqtheme/framework/popup/BasicPopup.java | 10 +-- .../qqtheme/framework/popup/ConfirmPopup.java | 19 +++++- .../qqtheme/framework/popup/PopupDialog.java | 6 +- .../framework/picker/DateTimePicker.java | 26 ++++---- .../qqtheme/framework/picker/TimePicker.java | 36 +++++++++-- screenshots/nestwheelview.jpg | Bin 0 -> 66204 bytes 15 files changed, 239 insertions(+), 61 deletions(-) create mode 100755 app/src/main/java/cn/qqtheme/androidpicker/NestActivity.java create mode 100755 app/src/main/res/layout/activity_nest.xml create mode 100755 screenshots/nestwheelview.jpg diff --git a/ChangeLog.md b/ChangeLog.md index 82a95c47..21ccb660 100755 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,15 @@ +### v1.3.0 - 2016.12.15 +支持设置选择器主体背景颜色; +所有选择器支持滑动实时监听; +所有选择器支持内嵌到其他视图容器; +重构单项选择器,数字选择器支持小数; +### v1.2.4 - 2016.11.23 +修复默认选中第一项时颜色不高亮问题; +修复联动选择器数组越界问题; +多级联动选择器支持设置各列比例; +时期及时间选择器内部逻辑修改; ### v1.2.3 - 2016.10.13 -修复日期选择器中当开始年份和结束年份相同时的Bug; +修复日期选择器中当开始年份和结束年份相同时的Bug; 修复年月日时分选择器的设置默认值时分没有补零的Bug; 支持所有选择器顶部高度及字号的设置; 修复日期选择器选中项显示有误问题,感谢@msdx; diff --git a/README.md b/README.md index 96a15917..ffc1a05d 100755 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ 安卓选择器类库,包括日期选择器、时间选择器、单项选择器、城市选择器、颜色选择器、文件选择器、目录选择器、数字选择器、星座选择器、生肖选择器等,可自定义顶部及底部界面,可自定义窗口动画。 欢迎大伙儿在[Issues](https://github.com/gzu-liyujiang/AndroidPicker/issues)提交你的意见或建议。 -欢迎Fork & Pull requests贡献您的代码。[查看更新日志](https://github.com/gzu-liyujiang/AndroidPicker/blob/master/ChangeLog.md)。 +欢迎Fork & Pull requests贡献您的代码,大家共同学习。 +[查看更新日志](https://github.com/gzu-liyujiang/AndroidPicker/blob/master/ChangeLog.md),×新版本未对旧版API作兼容处理,升级后若编译报错请根据错误提示更改×。 # Install “app”是测试用例;“library”包括WheelPicker、ColorPicker、FilePicker, @@ -20,14 +21,15 @@ dependencies { compile 'cn.qqtheme.framework:ColorPicker:latest.release' } ``` +若无法下载的话,可换[JitPack](https://jitpack.io/#gzu-liyujiang/AndroidPicker)的仓库试试! #### 需要学习或修改源代码,则下载本项目手动集成 下载示例项目后导入“library”下的相关module到你的项目(记得将module下的build.gradle修改类似于下面的内容,否则可能会报错找不到BuildToolsVersion): ```groovy apply plugin: 'com.android.library' android { - compileSdkVersion 22 - buildToolsVersion 22.0.1 + compileSdkVersion 23 + buildToolsVersion 23.0.1 defaultConfig { minSdkVersion 14 @@ -58,6 +60,8 @@ dependencies { ``` # Method +View getContentView() +得到选择器视图,可内嵌到其他视图容器 void setFillScreen(boolean fillScreen) 固定高度为屏幕的高 void setGravity(int gravity) @@ -116,7 +120,9 @@ void setTopLineColor(int topLineColor) 设置顶部标题栏下划线颜色 void setTopLineVisible(boolean topLineVisible) 设置顶部标题栏下划线是否显示 -...... +void setBackgroundColor(int backgroundColor) +设置主体背景颜色 +...... # Custom #### 自定义窗口进入退出动画(可选) @@ -321,14 +327,14 @@ https://github.com/wangjiegulu/WheelView https://github.com/jbruchanov/AndroidColorPicker # Screenshots -![自定义选择器效果图](/screenshots/custom.gif) +![滑轮选择器内嵌效果图](/screenshots/nestwheelview.jpg) +![自定义选择器效果图](/screenshots/custom.gif) ![日期选择器效果图](/screenshots/date.gif) ![日期选择器效果图](/screenshots/monthday.jpg) ![时间选择器效果图](/screenshots/time.gif) ![单项选择器效果图](/screenshots/option.gif) ![地址选择器效果图](/screenshots/address.gif) -![地址选择器效果图](/screenshots/address.png) -![数字选择器效果图](/screenshots/number.gif) +![数字选择器效果图](/screenshots/number.gif) ![星座选择器效果图](/screenshots/constellation.jpg) ![颜色选择器效果图](/screenshots/color.gif) ![文件选择器效果图](/screenshots/file.gif) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b2cf0480..ec09a8fb 100755 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,10 +1,10 @@ + xmlns:tools="http://schemas.android.com/tools" + package="cn.qqtheme.androidpicker"> - - + + - + - + + \ No newline at end of file diff --git a/app/src/main/java/cn/qqtheme/androidpicker/MainActivity.java b/app/src/main/java/cn/qqtheme/androidpicker/MainActivity.java index 0e5351bb..ac74fd61 100755 --- a/app/src/main/java/cn/qqtheme/androidpicker/MainActivity.java +++ b/app/src/main/java/cn/qqtheme/androidpicker/MainActivity.java @@ -47,17 +47,21 @@ private void showToast(String msg) { Toast.makeText(this, msg, Toast.LENGTH_SHORT).show(); } + public void onNestView(View view) { + startActivity(new Intent(this, NestActivity.class)); + } + public void onAnimationStyle(View view) { NumberPicker picker = new NumberPicker(this); picker.setAnimationStyle(R.style.Animation_CustomPopup); picker.setOffset(2);//偏移量 - picker.setRange(40, 100, 1);//数字范围 - picker.setSelectedItem(65); - picker.setLabel("Kg"); - picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() { + picker.setRange(10.50, 20.00, 1.5);//数字范围 + picker.setSelectedItem(10.50); + picker.setLabel("℃"); + picker.setOnNumberPickListener(new NumberPicker.OnNumberPickListener() { @Override - public void onOptionPicked(int position, String option) { - showToast(option); + public void onItemPicked(int index, Number item) { + showToast("index=" + index + ", item=" + item.doubleValue()); } }); picker.show(); @@ -66,17 +70,17 @@ public void onOptionPicked(int position, String option) { public void onAnimator(View view) { CustomHeaderAndFooterPicker picker = new CustomHeaderAndFooterPicker(this); picker.setGravity(Gravity.CENTER);//居中 - picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() { + picker.setOnItemPickListener(new OptionPicker.OnOptionPickListener() { @Override - public void onOptionPicked(int position, String option) { - showToast(option); + public void onItemPicked(int index, String item) { + showToast("index=" + index + ", item=" + item); } }); picker.show(); } public void onYearMonthDayPicker(View view) { - DatePicker picker = new DatePicker(this); + final DatePicker picker = new DatePicker(this); picker.setRangeStart(2016, 8, 29); picker.setRangeEnd(2022, 1, 11); picker.setSelectedItem(2016, 10, 14); @@ -86,6 +90,22 @@ public void onDatePicked(String year, String month, String day) { showToast(year + "-" + month + "-" + day); } }); + picker.setOnWheelListener(new DatePicker.OnWheelListener() { + @Override + public void onYearWheeled(int index, String year) { + picker.setTitleText(year + "-" + picker.getSelectedMonth() + "-" + picker.getSelectedDay()); + } + + @Override + public void onMonthWheeled(int index, String month) { + picker.setTitleText(picker.getSelectedYear() + "-" + month + "-" + picker.getSelectedDay()); + } + + @Override + public void onDayWheeled(int index, String day) { + picker.setTitleText(picker.getSelectedYear() + "-" + picker.getSelectedMonth() + "-" + day); + } + }); picker.show(); } @@ -152,10 +172,10 @@ public void onOptionPicker(View view) { picker.setOffset(2); picker.setSelectedIndex(0); picker.setTextSize(11); - picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() { + picker.setOnItemPickListener(new OptionPicker.OnOptionPickListener() { @Override - public void onOptionPicked(int position, String option) { - showToast(option); + public void onItemPicked(int index, String item) { + showToast("index=" + index + ", item=" + item); } }); picker.show(); @@ -213,11 +233,12 @@ public void onConstellationPicker(View view) { picker.setSubmitTextSize(22); picker.setTextColor(0xFFFF0000, 0xFF999999); picker.setLineColor(0xFFEE0000); + picker.setBackgroundColor(0xFFF1F1F1); picker.setSelectedItem("射手"); picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() { @Override - public void onOptionPicked(int position, String option) { - showToast(option); + public void onItemPicked(int index, String item) { + showToast("index=" + index + ", item=" + item); } }); picker.show(); @@ -231,10 +252,10 @@ public void onNumberPicker(View view) { picker.setRange(145, 200, 1);//数字范围 picker.setSelectedItem(172); picker.setLabel("厘米"); - picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() { + picker.setOnNumberPickListener(new NumberPicker.OnNumberPickListener() { @Override - public void onOptionPicked(int position, String option) { - showToast(option); + public void onItemPicked(int index, Number item) { + showToast("index=" + index + ", item=" + item.intValue()); } }); picker.show(); @@ -250,6 +271,7 @@ public void onAddress2Picker(View view) { String json = ConvertUtils.toString(getAssets().open("city2.json")); data.addAll(JSON.parseArray(json, Province.class)); AddressPicker picker = new AddressPicker(this, data); + picker.setCycleDisable(true); picker.setHideProvince(true); picker.setSelectedItem("贵州", "贵阳", "花溪"); picker.setOnAddressPickListener(new AddressPicker.OnAddressPickListener() { diff --git a/app/src/main/java/cn/qqtheme/androidpicker/NestActivity.java b/app/src/main/java/cn/qqtheme/androidpicker/NestActivity.java new file mode 100755 index 00000000..2c64e79f --- /dev/null +++ b/app/src/main/java/cn/qqtheme/androidpicker/NestActivity.java @@ -0,0 +1,56 @@ +package cn.qqtheme.androidpicker; + +import android.app.Activity; +import android.os.Bundle; +import android.view.ViewGroup; +import android.widget.TextView; + +import java.util.Arrays; + +import cn.qqtheme.framework.picker.TimePicker; +import cn.qqtheme.framework.widget.WheelView; + +/** + * 内嵌选择器 + *
+ * Author:李玉江[QQ:1032694760] + * DateTime:2016/12/16 00:42 + * Builder:Android Studio + */ +public class NestActivity extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_nest); + final TextView textView = (TextView) findViewById(R.id.wheelview_tips); + WheelView wheelView = (WheelView) findViewById(R.id.wheelview_single); + //noinspection RedundantArrayCreation + wheelView.setItems(Arrays.asList(new String[]{ + "贵州穿青人", + "少数民族", + "不在56少数个民族之列", + "第57个民族"})); + wheelView.setOnWheelListener(new WheelView.OnWheelListener() { + @Override + public void onSelected(boolean isUserScroll, int index, String item) { + textView.setText("index=" + index + ",item=" + item); + } + }); + final TimePicker picker = new TimePicker(this, TimePicker.HOUR_12); + picker.setOnWheelListener(new TimePicker.OnWheelListener() { + @Override + public void onHourWheeled(int index, String hour) { + textView.setText(hour + ":" + picker.getSelectedMinute()); + } + + @Override + public void onMinuteWheeled(int index, String minute) { + textView.setText(picker.getSelectedHour() + ":" + minute); + } + }); + ViewGroup viewGroup = (ViewGroup) findViewById(R.id.wheelview_container); + viewGroup.addView(picker.getContentView()); + } + +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index fe29bb17..fb5da924 100755 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -8,6 +8,12 @@ android:layout_height="wrap_content" android:orientation="vertical"> +