Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

调整手势滑动在首尾时的滚动边界判断范围, 加入xml预览, 提供xml属性, 支持label绘制在item的后面 #871

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
compileSdkVersion 32

defaultConfig {
applicationId "com.bigkoo.pickerviewdemo"
minSdkVersion 14
targetSdkVersion 26
targetSdkVersion 32
versionCode 1
versionName "1.0"
}
Expand All @@ -27,6 +27,6 @@ dependencies {
implementation project(':pickerview')
// implementation 'com.contrarywind:Android-PickerView:4.1.9'
// implementation 'com.contrarywind:wheelview:4.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.google.code.gson:gson:2.7'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.code.gson:gson:2.9.1'
}
16 changes: 10 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".JsonDataActivity"/>
<activity android:name=".FragmentTestActivity">


</activity>
<activity android:name=".TestCircleWheelViewActivity" />
<activity
android:name=".JsonDataActivity"
android:exported="false" />
<activity
android:name=".FragmentTestActivity"
android:exported="false"></activity>
<activity
android:name=".TestCircleWheelViewActivity"
android:exported="false" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

public class FragmentTestActivity extends AppCompatActivity {
private FragmentManager mFragmentManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.bigkoo.pickerviewdemo;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.Toast;

import com.bigkoo.pickerview.adapter.ArrayWheelAdapter;
Expand All @@ -25,7 +25,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
setContentView(R.layout.activity_test_circle_wheelview);

WheelView wheelView = findViewById(R.id.wheelview);
wheelView.setTextSize(20);
wheelView.setTextSizeDp(20);
wheelView.setLineSpacingMultiplier(2f);
// wheelView.setDividerWidth(6);
wheelView.setDividerType(WheelView.DividerType.CIRCLE);
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/com/bigkoo/pickerviewdemo/TestFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'com.android.tools.build:gradle:7.2.2'
// classpath "com.novoda:bintray-release:0.9.1"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
//classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# org.gradle.parallel=true
android.enableJetifier=false
android.useAndroidX=true
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
8 changes: 4 additions & 4 deletions pickerview/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
//apply plugin: 'com.github.dcendents.android-maven'
//apply plugin: 'com.novoda.bintray-release'//添加JCenter插件



android {
compileSdkVersion 26
compileSdkVersion 32

defaultConfig {
minSdkVersion 14
targetSdkVersion 26
targetSdkVersion 32
versionCode 34
versionName "4.1.9"
}
Expand Down Expand Up @@ -46,5 +46,5 @@ dependencies {
// compile fileTree(include: ['*.jar'], dir: 'libs')
api project(path: ':wheelview')
// api 'com.contrarywind:wheelview:4.1.0'
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'androidx.annotation:annotation:1.5.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import android.content.Context;
import android.graphics.Typeface;
import android.support.annotation.ColorInt;
import androidx.annotation.ColorInt;
import android.view.View;
import android.view.ViewGroup;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.bigkoo.pickerview.builder;

import android.content.Context;
import android.support.annotation.ColorInt;
import androidx.annotation.ColorInt;
import android.view.View;
import android.view.ViewGroup;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public PickerOptions(int buildType) {

public int textSizeSubmitCancel = 17;//确定取消按钮大小
public int textSizeTitle = 18;//标题文字大小
public int textSizeContent = 18;//内容文字大小
public int textSizeContent = 18;//内容文字大小 dp

public int textColorOut = 0xFFa8a8a8; //分割线以外的文字颜色
public int textColorCenter = 0xFF2a2a2a; //分割线之间的文字颜色
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ private void initView(Context context) {
}

private void initWheelTime(LinearLayout timePickerView) {
wheelTime = new WheelTime(timePickerView, mPickerOptions.type, mPickerOptions.textGravity, mPickerOptions.textSizeContent);
wheelTime = new WheelTime(timePickerView, mPickerOptions.type, mPickerOptions.textGravity,
mPickerOptions.textSizeContent * timePickerView.getContext().getResources().getDisplayMetrics().density);
if (mPickerOptions.timeSelectChangeListener != null) {
wheelTime.setSelectChangeCallback(new ISelectTimeCallback() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ public void onItemSelected(int index) {
}
}

public void setTextContentSize(int textSize) {
wv_option1.setTextSize(textSize);
wv_option2.setTextSize(textSize);
wv_option3.setTextSize(textSize);
public void setTextContentSize(float textSize) {
wv_option1.setTextSizeDp(textSize);
wv_option2.setTextSizeDp(textSize);
wv_option3.setTextSizeDp(textSize);
}

private void setLineSpacingMultiplier() {
Expand Down
19 changes: 11 additions & 8 deletions pickerview/src/main/java/com/bigkoo/pickerview/view/WheelTime.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bigkoo.pickerview.view;

import androidx.annotation.Px;
import android.view.View;

import com.bigkoo.pickerview.R;
Expand Down Expand Up @@ -45,12 +46,13 @@ public class WheelTime {
private int endDay = DEFAULT_END_DAY; //表示31天的
private int currentYear;

private int textSize;
@Px
private float textSize;

private boolean isLunarCalendar = false;
private ISelectTimeCallback mSelectChangeCallback;

public WheelTime(View view, boolean[] type, int gravity, int textSize) {
public WheelTime(View view, boolean[] type, int gravity, @Px float textSize) {
super();
this.view = view;
this.type = type;
Expand Down Expand Up @@ -571,7 +573,6 @@ private void setReDay(int year_num, int monthNum, int startD, int endD, List<Str
}
}


private void setContentTextSize() {
wv_day.setTextSize(textSize);
wv_month.setTextSize(textSize);
Expand All @@ -581,7 +582,6 @@ private void setContentTextSize() {
wv_seconds.setTextSize(textSize);
}


public void setLabels(String label_year, String label_month, String label_day, String label_hours, String label_mins, String label_seconds) {
if (isLunarCalendar) {
return;
Expand Down Expand Up @@ -786,10 +786,13 @@ public void setRangDate(Calendar startDate, Calendar endDate) {
} else if (startDate != null && endDate != null) {
this.startYear = startDate.get(Calendar.YEAR);
this.endYear = endDate.get(Calendar.YEAR);
this.startMonth = startDate.get(Calendar.MONTH) + 1;
this.endMonth = endDate.get(Calendar.MONTH) + 1;
this.startDay = startDate.get(Calendar.DAY_OF_MONTH);
this.endDay = endDate.get(Calendar.DAY_OF_MONTH);
if (this.startYear == this.endYear) {
//只有在开始年份和结束年份一样的时候, 在设置月/日限制, 才有意义. 2022-2-12
this.startMonth = startDate.get(Calendar.MONTH) + 1;
this.endMonth = endDate.get(Calendar.MONTH) + 1;
this.startDay = startDate.get(Calendar.DAY_OF_MONTH);
this.endDay = endDate.get(Calendar.DAY_OF_MONTH);
}
}

}
Expand Down
8 changes: 4 additions & 4 deletions wheelview/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
//apply plugin: 'com.github.dcendents.android-maven'
//apply plugin: 'com.novoda.bintray-release'//添加插件



android {
compileSdkVersion 26
compileSdkVersion 32

defaultConfig {
minSdkVersion 14
targetSdkVersion 26
targetSdkVersion 32
versionCode 31
versionName "4.1.0"
}
Expand Down Expand Up @@ -44,5 +44,5 @@ android {

dependencies {
// compile fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'androidx.annotation:annotation:1.5.0'
}
20 changes: 20 additions & 0 deletions wheelview/src/main/java/com/contrarywind/adapter/IWheelDraw.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.contrarywind.adapter;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;

import com.contrarywind.view.WheelView;

/**
* @author <a href="mailto:angcyo@126.com">angcyo</a>
* @since 2022/12/30
*/
public interface IWheelDraw {

/**
* 绘制文本时, 额外需要绘制的东西
*/
void onDrawOnText(WheelView wheelView, Canvas canvas, String text, float textDrawX, float textDrawY, Paint textDrawPaint, int index, Rect textBounds);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.contrarywind.adapter;

import java.util.ArrayList;

/**
* Email:angcyo@126.com
*
* @author angcyo
* @date 2020/03/12
* Copyright (c) 2019 ShenZhen O&M Cloud Co., Ltd. All rights reserved.
*/
public class PreviewAdapter implements WheelAdapter<String> {

private ArrayList<String> itemList = new ArrayList<>();

public PreviewAdapter() {
for (int i = 0; i < 5; i++) {
itemList.add("Item " + i);
}
}

@Override
public int getItemsCount() {
return itemList.size();
}

@Override
public String getItem(int index) {
return itemList.get(index);
}

@Override
public int indexOf(String o) {
return itemList.indexOf(o);
}
}