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

Fixed on click scroll when selected text size and general text size are different #192

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ko_fi: shawnlin
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
The android library that provides a simple and customizable NumberPicker.
It's based on [android.widget.NumberPicker](https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/widget/NumberPicker.java).

[![Platform](http://img.shields.io/badge/platform-android-brightgreen.svg?style=flat)](http://developer.android.com/index.html) [![Language](http://img.shields.io/badge/language-java-orange.svg?style=flat)](http://www.oracle.com/technetwork/java/javase/downloads/index.html) [![](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-NumberPicker-green.svg?style=true)](https://android-arsenal.com/details/1/3718) [![API](https://img.shields.io/badge/API-15%2B-blue.svg?style=flat)](https://android-arsenal.com/api?level=15) [![Download](https://api.bintray.com/packages/shawnlin013/maven/number-picker/images/download.svg)](https://bintray.com/shawnlin013/maven/number-picker/_latestVersion) [![CircleCI](https://circleci.com/gh/ShawnLin013/NumberPicker.svg?style=svg)](https://circleci.com/gh/ShawnLin013/NumberPicker)
[![Platform](http://img.shields.io/badge/platform-android-brightgreen.svg?style=flat)](http://developer.android.com/index.html) [![Language](http://img.shields.io/badge/language-java-orange.svg?style=flat)](http://www.oracle.com/technetwork/java/javase/downloads/index.html) [![](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-NumberPicker-green.svg?style=true)](https://android-arsenal.com/details/1/3718) [![API](https://img.shields.io/badge/API-15%2B-blue.svg?style=flat)](https://android-arsenal.com/api?level=15) ![Maven Central](https://img.shields.io/maven-central/v/io.github.ShawnLin013/number-picker) [![CircleCI](https://circleci.com/gh/ShawnLin013/NumberPicker.svg?style=svg)](https://circleci.com/gh/ShawnLin013/NumberPicker)
[![GitHub stars](https://img.shields.io/github/stars/ShawnLin013/NumberPicker)](https://github.com/ShawnLin013/NumberPicker/stargazers) [![GitHub forks](https://img.shields.io/github/forks/ShawnLin013/NumberPicker)](https://github.com/ShawnLin013/NumberPicker/network)

<img src="https://github.com/ShawnLin013/NumberPicker/blob/master/screenshot/number-picker-theme.png">

Expand Down Expand Up @@ -138,7 +139,7 @@ add `xmlns:app="http://schemas.android.com/apk/res-auto"`

### Attributes

|attribute name|attribute description|defalut|
|attribute name|attribute description|default|
|:---:|:---:|:---:|
|np_width|The width of this widget.|
|np_height|The height of this widget.|
Expand Down Expand Up @@ -183,12 +184,12 @@ Add the dependency in your `build.gradle`
```gradle
buildscript {
repositories {
jcenter()
mavenCentral()
}
}

dependencies {
implementation 'com.shawnlin:number-picker:2.4.12'
implementation 'io.github.ShawnLin013:number-picker:2.4.13'
}
```

Expand Down
11 changes: 5 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.2'
classpath "guru.stefma.bintrayrelease:bintrayrelease:1.1.2"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.android.tools.build:gradle:8.2.2'
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.28.0'
}
}

allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
}
}

Expand Down
34 changes: 23 additions & 11 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
VERSION_CODE=20
VERSION_NAME=2.4.12
android.useAndroidX=true
android.enableJetifier=true
android.debug.obsoleteApi=true

GROUP_ID=com.shawnlin
ARTIFACT_ID=number-picker
VERSION_CODE=21
VERSION_NAME=2.4.13

GROUP=io.github.ShawnLin013
POM_ARTIFACT_ID=number-picker

POM_NAME=Number Picker
POM_PACKAGING=aar
POM_DESCRIPTION=The android library that provides a simple and customizable NumberPicker.
POM_INCEPTION_YEAR=2021
POM_URL=https://github.com/ShawnLin013/NumberPicker
POM_LICENSE_NAME=MIT
POM_LICENSE_URL=https://opensource.org/licenses/MIT
POM_LICENSE_DIST=repo
POM_DEVELOPER_ID=shawnlin013
android.useAndroidX=true
android.enableJetifier=true
android.debug.obsoleteApi=true

POM_LICENCE_NAME=MIT
POM_LICENCE_URL=https://opensource.org/licenses/MIT
POM_LICENCE_DIST=repo

POM_SCM_URL=https://github.com/ShawnLin013/NumberPicker
POM_SCM_CONNECTION=scm:[email protected]:ShawnLin013/NumberPicker.git
POM_SCM_DEV_CONNECTION=scm:[email protected]:ShawnLin013/NumberPicker.git

POM_DEVELOPER_ID=ShawnLin013
POM_DEVELOPER_NAME=Shawn Lin
POM_DEVELOPER_URL=https://github.com/ShawnLin013/NumberPicker
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Sat Jun 13 03:38:47 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
45 changes: 26 additions & 19 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
apply plugin: 'com.android.library'
apply plugin: "guru.stefma.bintrayrelease"
plugins {
id 'com.vanniktech.maven.publish'
id 'com.android.library'
}

android {
compileSdkVersion 30

defaultConfig {
compileSdk 34
minSdkVersion 15
targetSdkVersion 30
targetSdkVersion 34
versionCode VERSION_CODE as int
versionName VERSION_NAME
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

namespace 'com.shawnlin.numberpicker'
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
}

version = VERSION_NAME
group = GROUP_ID
androidArtifact {
artifactId = ARTIFACT_ID
license {
name = POM_LICENSE_NAME
url = POM_LICENSE_URL
distribution = POM_LICENSE_DIST
publishing {
publications {
myMaven(MavenPublication) {
groupId GROUP
artifactId POM_ARTIFACT_ID
version VERSION_NAME
artifact("$buildDir/outputs/aar/library-release.aar")
}
}
}
publish {
userOrg = POM_DEVELOPER_ID
desc = POM_DESCRIPTION
website = POM_URL
}

tasks.named("publishMyMavenPublicationToMavenLocal") {
dependsOn tasks.named("bundleReleaseAar")
}
4 changes: 1 addition & 3 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
<manifest package="com.shawnlin.numberpicker"
xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>
<manifest />
20 changes: 9 additions & 11 deletions library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -1110,11 +1110,9 @@ public boolean onTouchEvent(MotionEvent event) {
int eventX = (int) event.getX();
int deltaMoveX = (int) Math.abs(eventX - mLastDownEventX);
if (deltaMoveX <= mTouchSlop) {
int selectorIndexOffset = (eventX / mSelectorElementSize)
- mWheelMiddleItemIndex;
if (selectorIndexOffset > 0) {
if (eventX > mRightDividerRight) {
changeValueByOne(true);
} else if (selectorIndexOffset < 0) {
} else if (eventX < mLeftDividerLeft) {
changeValueByOne(false);
} else {
ensureScrollWheelAdjusted();
Expand All @@ -1133,11 +1131,9 @@ public boolean onTouchEvent(MotionEvent event) {
int eventY = (int) event.getY();
int deltaMoveY = (int) Math.abs(eventY - mLastDownEventY);
if (deltaMoveY <= mTouchSlop) {
int selectorIndexOffset = (eventY / mSelectorElementSize)
- mWheelMiddleItemIndex;
if (selectorIndexOffset > 0) {
if (eventY > mBottomDividerBottom) {
changeValueByOne(true);
} else if (selectorIndexOffset < 0) {
} else if (eventY < mTopDividerTop) {
changeValueByOne(false);
} else {
ensureScrollWheelAdjusted();
Expand Down Expand Up @@ -2077,16 +2073,18 @@ private void initializeSelectorWheelIndices() {
* @param notifyChange Whether to notify if the current value changed.
*/
private void setValueInternal(int current, boolean notifyChange) {
if (mValue == current) {
return;
}
// Wrap around the values if we go past the start or end
if (mWrapSelectorWheel) {
current = getWrappedSelectorIndex(current);
} else {
current = Math.max(current, mMinValue);
current = Math.min(current, mMaxValue);
}

if (mValue == current) {
return;
}

int previous = mValue;
mValue = current;
// If we're flinging, we'll update the text view at the end when it becomes visible
Expand Down
11 changes: 6 additions & 5 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 30

defaultConfig {
applicationId "com.shawnlin.numberpicker.sample"
compileSdk 34
minSdkVersion 15
targetSdkVersion 30
targetSdkVersion 34
versionCode 1
versionName "1.0"
}
Expand All @@ -16,11 +15,13 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

namespace 'com.shawnlin.numberpicker.sample'
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0-alpha03'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0-beta01'
implementation project(':library')
}
3 changes: 2 additions & 1 deletion sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.shawnlin.numberpicker.sample"
<manifest
xmlns:android="http://schemas.android.com/apk/res/android">

<application
Expand All @@ -10,6 +10,7 @@
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar">
Expand Down