diff --git a/README.md b/README.md index 9017dead..ac774019 100755 --- a/README.md +++ b/README.md @@ -22,6 +22,20 @@ dependencies { } ``` 若无法下载的话,可换[JitPack](https://jitpack.io/#gzu-liyujiang/AndroidPicker)的仓库试试! +``` +repositories { + maven { + url "https://www.jitpack.io" + } +} +``` +``` +dependencies { + compile 'com.github.gzu-liyujiang.AndroidPicker:WheelPicker:版本号' + compile 'com.github.gzu-liyujiang.AndroidPicker:FilePicker:版本号' + compile 'com.github.gzu-liyujiang.AndroidPicker:ColorPicker:版本号' +} +``` #### 需要学习或修改源代码,则下载本项目手动集成 下载示例项目后导入“library”下的相关module到你的项目(记得将module下的build.gradle修改类似于下面的内容,否则可能会报错找不到BuildToolsVersion): ```groovy @@ -62,7 +76,6 @@ dependencies { -keep class cn.qqtheme.framework.entity.** { *;} ``` - # Method android.view.View getContentView() 得到选择器视图,可内嵌到其他视图容器 @@ -131,6 +144,20 @@ void setBackgroundColor(int backgroundColor) # Custom #### 自定义视图 WheelView这个类是滑轮选择器的核心,可以扩展出各种效果,参见demo的[NestActivity.java](https://github.com/gzu-liyujiang/AndroidPicker/blob/master/app/src/main/java/cn/qqtheme/androidpicker/NestActivity.java)。 +```java + WheelView wheelView = (WheelView) findViewById(R.id.wheelview); + wheelView.setItems(Arrays.asList(new String[]{ + "贵州穿青人", + "少数民族", + "不在56个少数民族之列", + "第57个民族"})); + wheelView.setOnWheelListener(new WheelView.OnWheelListener() { + @Override + public void onSelected(boolean isUserScroll, int index, String item) { + // do something + } + }); +``` #### 自定义窗口进入退出动画 推荐使用[ViewAnimator](https://github.com/gzu-liyujiang/ViewAnimator)这个动画库来实现: ```groovy diff --git a/app/build.gradle b/app/build.gradle index 6a93858e..3185c6f0 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -30,4 +30,7 @@ dependencies { // compile 'cn.qqtheme.framework:WheelPicker:latest.release' // compile 'cn.qqtheme.framework:FilePicker:latest.release' // compile 'cn.qqtheme.framework:ColorPicker:latest.release' +// compile 'com.github.gzu-liyujiang.AndroidPicker:WheelPicker:1.3.1' +// compile 'com.github.gzu-liyujiang.AndroidPicker:FilePicker:1.3.1' +// compile 'com.github.gzu-liyujiang.AndroidPicker:ColorPicker:1.3.1' } diff --git a/app/src/main/java/cn/qqtheme/androidpicker/MainActivity.java b/app/src/main/java/cn/qqtheme/androidpicker/MainActivity.java index ac74fd61..785cf489 100755 --- a/app/src/main/java/cn/qqtheme/androidpicker/MainActivity.java +++ b/app/src/main/java/cn/qqtheme/androidpicker/MainActivity.java @@ -60,7 +60,7 @@ public void onAnimationStyle(View view) { picker.setLabel("℃"); picker.setOnNumberPickListener(new NumberPicker.OnNumberPickListener() { @Override - public void onItemPicked(int index, Number item) { + public void onNumberPicked(int index, Number item) { showToast("index=" + index + ", item=" + item.doubleValue()); } }); @@ -70,10 +70,10 @@ public void onItemPicked(int index, Number item) { public void onAnimator(View view) { CustomHeaderAndFooterPicker picker = new CustomHeaderAndFooterPicker(this); picker.setGravity(Gravity.CENTER);//居中 - picker.setOnItemPickListener(new OptionPicker.OnOptionPickListener() { + picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() { @Override - public void onItemPicked(int index, String item) { - showToast("index=" + index + ", item=" + item); + public void onOptionPicked(int position, String option) { + showToast("index=" + position + ", item=" + option); } }); picker.show(); @@ -172,9 +172,9 @@ public void onOptionPicker(View view) { picker.setOffset(2); picker.setSelectedIndex(0); picker.setTextSize(11); - picker.setOnItemPickListener(new OptionPicker.OnOptionPickListener() { + picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() { @Override - public void onItemPicked(int index, String item) { + public void onOptionPicked(int index, String item) { showToast("index=" + index + ", item=" + item); } }); @@ -237,7 +237,7 @@ public void onConstellationPicker(View view) { picker.setSelectedItem("射手"); picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() { @Override - public void onItemPicked(int index, String item) { + public void onOptionPicked(int index, String item) { showToast("index=" + index + ", item=" + item); } }); @@ -254,7 +254,7 @@ public void onNumberPicker(View view) { picker.setLabel("厘米"); picker.setOnNumberPickListener(new NumberPicker.OnNumberPickListener() { @Override - public void onItemPicked(int index, Number item) { + public void onNumberPicked(int index, Number item) { showToast("index=" + index + ", item=" + item.intValue()); } }); diff --git a/app/src/main/java/cn/qqtheme/androidpicker/NestActivity.java b/app/src/main/java/cn/qqtheme/androidpicker/NestActivity.java index 2c64e79f..466ff6d1 100755 --- a/app/src/main/java/cn/qqtheme/androidpicker/NestActivity.java +++ b/app/src/main/java/cn/qqtheme/androidpicker/NestActivity.java @@ -29,7 +29,7 @@ protected void onCreate(Bundle savedInstanceState) { wheelView.setItems(Arrays.asList(new String[]{ "贵州穿青人", "少数民族", - "不在56少数个民族之列", + "不在56个少数民族之列", "第57个民族"})); wheelView.setOnWheelListener(new WheelView.OnWheelListener() { @Override diff --git a/library/WheelPicker/src/main/java/cn/qqtheme/framework/picker/NumberPicker.java b/library/WheelPicker/src/main/java/cn/qqtheme/framework/picker/NumberPicker.java index 667376c0..1391c1d1 100755 --- a/library/WheelPicker/src/main/java/cn/qqtheme/framework/picker/NumberPicker.java +++ b/library/WheelPicker/src/main/java/cn/qqtheme/framework/picker/NumberPicker.java @@ -57,7 +57,14 @@ public void setOnNumberPickListener(OnNumberPickListener listener) { super.setOnItemPickListener(listener); } - public interface OnNumberPickListener extends OnItemPickListener { + public static abstract class OnNumberPickListener implements OnItemPickListener { + + public abstract void onNumberPicked(int index, Number item); + + @Override + public final void onItemPicked(int index, Number item) { + onNumberPicked(index, item); + } } diff --git a/library/WheelPicker/src/main/java/cn/qqtheme/framework/picker/OptionPicker.java b/library/WheelPicker/src/main/java/cn/qqtheme/framework/picker/OptionPicker.java index db6709a4..3504922d 100755 --- a/library/WheelPicker/src/main/java/cn/qqtheme/framework/picker/OptionPicker.java +++ b/library/WheelPicker/src/main/java/cn/qqtheme/framework/picker/OptionPicker.java @@ -24,7 +24,14 @@ public void setOnOptionPickListener(OnOptionPickListener listener) { super.setOnItemPickListener(listener); } - public interface OnOptionPickListener extends OnItemPickListener { + public static abstract class OnOptionPickListener implements OnItemPickListener { + + public abstract void onOptionPicked(int index, String item); + + @Override + public final void onItemPicked(int index, String item) { + onOptionPicked(index, item); + } } diff --git a/library/WheelPicker/src/main/java/cn/qqtheme/framework/widget/WheelView.java b/library/WheelPicker/src/main/java/cn/qqtheme/framework/widget/WheelView.java index b1479f06..007aa7bc 100755 --- a/library/WheelPicker/src/main/java/cn/qqtheme/framework/widget/WheelView.java +++ b/library/WheelPicker/src/main/java/cn/qqtheme/framework/widget/WheelView.java @@ -93,10 +93,7 @@ private void init(Context context) { // 2015/12/15 去掉ScrollView的阴影 setFadingEdgeLength(0); - if (Build.VERSION.SDK_INT >= 9) { - setOverScrollMode(OVER_SCROLL_NEVER); - } - + setOverScrollMode(OVER_SCROLL_NEVER); setVerticalScrollBarEnabled(false); views = new LinearLayout(context); @@ -375,6 +372,14 @@ public int getSelectedIndex() { return selectedIndex - offset; } + /** + * @deprecated use {@link #setOnWheelListener(OnWheelListener)} instead + */ + @Deprecated + public void setOnWheelViewListener(OnWheelViewListener onWheelListener) { + setOnWheelListener(onWheelListener); + } + public void setOnWheelListener(OnWheelListener onWheelListener) { this.onWheelListener = onWheelListener; } @@ -383,13 +388,20 @@ public interface OnWheelListener { /** * 滑动选择回调 * - * @param isUserScroll 是否用户手动滚动,用于联动效果判断是否自动重置选中项 - * @param index 当前选择项的索引 - * @param item 当前选择项的值 + * @param isUserScroll 是否用户手动滚动,用于联动效果判断是否自动重置选中项 + * @param index 当前选择项的索引 + * @param item 当前选择项的值 */ void onSelected(boolean isUserScroll, int index, String item); } + /** + * @deprecated use {@link OnWheelListener} instead + */ + @Deprecated + public interface OnWheelViewListener extends OnWheelListener { + } + private class ScrollerTask implements Runnable { @Override diff --git a/publish.gradle b/publish.gradle index 4c060311..fd5e70c6 100755 --- a/publish.gradle +++ b/publish.gradle @@ -57,7 +57,7 @@ publishing { publications { MyPublication(MavenPublication) { artifactId project.pomArtifactId - //artifact "${buildDir}/outputs/aar/${project.pomArtifactId}-release.aar" + artifact "${buildDir}/outputs/aar/${project.pomArtifactId}-release.aar" artifact javadocJar artifact sourcesJar diff --git a/screenshots/nestwheelview.jpg b/screenshots/nestwheelview.jpg index 8d862c7b..741045f7 100755 Binary files a/screenshots/nestwheelview.jpg and b/screenshots/nestwheelview.jpg differ