Skip to content

Commit

Permalink
兼容旧版api
Browse files Browse the repository at this point in the history
  • Loading branch information
liyujiang-gzu committed Dec 17, 2016
1 parent b93b62d commit 2057290
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 20 deletions.
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -62,7 +76,6 @@ dependencies {
-keep class cn.qqtheme.framework.entity.** { *;}
```

# Method
android.view.View getContentView()
得到选择器视图,可内嵌到其他视图容器
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
16 changes: 8 additions & 8 deletions app/src/main/java/cn/qqtheme/androidpicker/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
});
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
});
Expand Down Expand Up @@ -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);
}
});
Expand All @@ -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());
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected void onCreate(Bundle savedInstanceState) {
wheelView.setItems(Arrays.asList(new String[]{
"贵州穿青人",
"少数民族",
"不在56少数个民族之列",
"不在56个少数民族之列",
"第57个民族"}));
wheelView.setOnWheelListener(new WheelView.OnWheelListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ public void setOnNumberPickListener(OnNumberPickListener listener) {
super.setOnItemPickListener(listener);
}

public interface OnNumberPickListener extends OnItemPickListener<Number> {
public static abstract class OnNumberPickListener implements OnItemPickListener<Number> {

public abstract void onNumberPicked(int index, Number item);

@Override
public final void onItemPicked(int index, Number item) {
onNumberPicked(index, item);
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ public void setOnOptionPickListener(OnOptionPickListener listener) {
super.setOnItemPickListener(listener);
}

public interface OnOptionPickListener extends OnItemPickListener<String> {
public static abstract class OnOptionPickListener implements OnItemPickListener<String> {

public abstract void onOptionPicked(int index, String item);

@Override
public final void onItemPicked(int index, String item) {
onOptionPicked(index, item);
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Binary file modified screenshots/nestwheelview.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2057290

Please sign in to comment.