Skip to content

Commit 6b1d89f

Browse files
authored
Merge pull request #10 from techery/fix/vertical_seekbar_orientation
Fix vertical seekbar orientation offset
2 parents b6acea4 + e18490c commit 6b1d89f

13 files changed

Lines changed: 87 additions & 118 deletions

File tree

.idea/codeStyleSettings.xml

Lines changed: 5 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
1-
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2-
31
buildscript {
42
repositories {
53
jcenter()
64
}
75
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.1.0'
9-
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
6+
classpath 'com.android.tools.build:gradle:2.3.3'
7+
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
108
}
119
}
1210

1311
ext {
14-
compileSdkVersion = 23
15-
buildToolsVersion = '23.0.3'
12+
compileSdkVersion = 25
13+
buildToolsVersion = '25.0.3'
1614
minSdkVersion = 15
17-
targetSdkVersion = 23
15+
targetSdkVersion = 25
16+
17+
supportPackageVersion = '25.4.0'
18+
}
19+
20+
allprojects {
21+
repositories {
22+
jcenter()
23+
maven {
24+
url "https://maven.google.com"
25+
}
26+
}
1827
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Thu Jan 28 11:55:05 GMT+02:00 2016
1+
#Thu Jul 20 18:17:50 EEST 2017
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-all.zip

library-addition/build.gradle

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,9 @@ android {
99
minSdkVersion rootProject.ext.minSdkVersion
1010
targetSdkVersion rootProject.ext.targetSdkVersion
1111
}
12-
buildTypes {
13-
release {
14-
minifyEnabled false
15-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
16-
}
17-
}
18-
}
19-
20-
repositories {
21-
jcenter()
2212
}
2313

2414
dependencies {
2515
compile project(':library')
26-
compile 'com.h6ah4i.android.widget.verticalseekbar:verticalseekbar:0.6.0'
27-
}
28-
29-
30-
// build a jar with source files
31-
task sourcesJar(type: Jar) {
32-
from android.sourceSets.main.java.srcDirs
33-
classifier = 'sources'
34-
}
35-
artifacts {
36-
archives sourcesJar
16+
compile 'com.h6ah4i.android.widget.verticalseekbar:verticalseekbar:0.7.2'
3717
}

library-addition/src/main/java/io/techery/progresshint/addition/HorizontalProgressHintDelegate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public HorizontalProgressHintDelegate(SeekBar seekBar, AttributeSet attrs, int d
3232
}
3333

3434
private int getHorizontalOffset(int progress) {
35-
return getFollowPosition(progress) - mPopupView.getMeasuredWidth() / 2 + mSeekBar.getHeight() / 2;
35+
return getFollowPosition(progress) - mPopupView.getMeasuredWidth() / 2 + mSeekBar.getHeight() / 2 + 15;
3636
}
3737

3838
private int getVerticalOffset() {

library-addition/src/main/java/io/techery/progresshint/addition/VerticalProgressHintDelegate.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
import android.graphics.Point;
44
import android.graphics.PointF;
5+
import android.support.annotation.IntDef;
56
import android.util.AttributeSet;
67
import android.view.MotionEvent;
78
import android.widget.SeekBar;
89
import io.techery.progresshint.ProgressHintDelegate;
10+
import java.lang.annotation.Retention;
11+
import java.lang.annotation.RetentionPolicy;
912

1013
public class VerticalProgressHintDelegate extends ProgressHintDelegate {
1114

@@ -36,29 +39,36 @@ public VerticalProgressHintDelegate(SeekBar seekBar, AttributeSet attrs, int def
3639

3740
private int getHorizontalOffset() {
3841
switch (getOrientation()) {
39-
case 1:
42+
case CW:
4043
return mPopupOffset;
41-
case -1:
44+
case CCW:
4245
return mSeekBar.getHeight() + mPopupOffset;
46+
default:
47+
throw new IllegalStateException("This widget orientation is not supported");
4348
}
44-
return 0;
4549
}
4650

4751
private int getVerticalOffset(int progress) {
48-
int yOddOffset = 0;
52+
int followPosition = getFollowPosition(progress);
53+
int yOddOffset;
4954
switch (getOrientation()) {
50-
case 1:
51-
//yOddOffset = offsetPadding + mPopupView.getMeasuredHeight() / 2;
52-
yOddOffset = mPopupView.getMeasuredHeight() / 2 + mSeekBar.getHeight() / 2 + 1;
53-
break;
54-
case -1:
55-
yOddOffset = mPopupView.getMeasuredHeight() / 2 - mSeekBar.getHeight() / 2 - 1;
56-
break;
55+
case CW:
56+
yOddOffset = mPopupView.getMeasuredHeight() / 2 + mSeekBar.getHeight() / 2 - 15;
57+
return followPosition - yOddOffset;
58+
case CCW:
59+
yOddOffset = mPopupView.getMeasuredHeight() / 2 + mSeekBar.getHeight() * 2;
60+
return -followPosition - yOddOffset;
61+
default:
62+
throw new IllegalStateException("This widget orientation is not supported");
5763
}
58-
return getFollowPosition(progress) - yOddOffset;
5964
}
6065

61-
private int getOrientation() {
62-
return (int) (mSeekBar.getRotation() / 90f);
66+
@VerticalOrientation private int getOrientation() {
67+
return (int) (mSeekBar.getRotation() / 90f) == 1 ? CW : CCW;
6368
}
69+
70+
@Retention(RetentionPolicy.SOURCE) @IntDef({ CW, CCW }) public @interface VerticalOrientation {}
71+
72+
private static final int CW = 1;
73+
private static final int CCW = 0;
6474
}

library-addition/src/main/java/io/techery/progresshint/addition/widget/SeekBar.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,4 @@ private void init(AttributeSet attrs, int defStyle) {
3939
public ProgressHintDelegate getHintDelegate() {
4040
return hintDelegate;
4141
}
42-
4342
}

library-addition/src/main/java/io/techery/progresshint/addition/widget/VerticalSeekBar.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,4 @@ private void init(AttributeSet attrs, int defStyle) {
4040
public ProgressHintDelegate getHintDelegate() {
4141
return hintDelegate;
4242
}
43-
4443
}

library/build.gradle

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,8 @@ android {
99
minSdkVersion rootProject.ext.minSdkVersion
1010
targetSdkVersion rootProject.ext.targetSdkVersion
1111
}
12-
buildTypes {
13-
release {
14-
minifyEnabled false
15-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
16-
}
17-
}
18-
}
19-
20-
// build a jar with source files
21-
task sourcesJar(type: Jar) {
22-
from android.sourceSets.main.java.srcDirs
23-
classifier = 'sources'
24-
}
25-
artifacts {
26-
archives sourcesJar
27-
}
28-
29-
repositories {
30-
jcenter()
3112
}
3213

3314
dependencies {
34-
compile 'com.android.support:support-annotations:23.4.0'
15+
provided "com.android.support:support-annotations:$rootProject.ext.supportPackageVersion"
3516
}

library/src/main/java/io/techery/progresshint/ProgressHintDelegate.java

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ public abstract class ProgressHintDelegate implements OnSeekBarChangeListener {
4545
public static final int POPUP_FIXED = 1;
4646
public static final int POPUP_FOLLOW = 0;
4747

48-
@Retention(RetentionPolicy.SOURCE) @IntDef({ POPUP_FIXED, POPUP_FOLLOW })
49-
public @interface PopupStyle {
50-
}
48+
@Retention(RetentionPolicy.SOURCE) @IntDef({ POPUP_FIXED, POPUP_FOLLOW }) public @interface PopupStyle {}
5149

5250
private SeekBarHintAdapter mHintAdapter;
5351
private SeekBarHintAttacher mHintAttacher;
@@ -56,35 +54,29 @@ public abstract class ProgressHintDelegate implements OnSeekBarChangeListener {
5654
private Handler handler = new Handler();
5755
private boolean isTracking;
5856

59-
public ProgressHintDelegate(SeekBar seekBar, int mPopupLayout, int mPopupOffset,
60-
boolean mPopupAlwaysShown, boolean mPopupDraggable, int mPopupStyle, int mPopupAnimStyle) {
61-
initDelegate(seekBar, mPopupLayout, mPopupOffset, mPopupAlwaysShown, mPopupDraggable,
62-
mPopupStyle, mPopupAnimStyle, ProgressHintDelegate.DEFAULT_HINT_ADAPTER);
57+
public ProgressHintDelegate(SeekBar seekBar, int mPopupLayout, int mPopupOffset, boolean mPopupAlwaysShown, boolean mPopupDraggable,
58+
int mPopupStyle, int mPopupAnimStyle) {
59+
initDelegate(seekBar, mPopupLayout, mPopupOffset, mPopupAlwaysShown, mPopupDraggable, mPopupStyle, mPopupAnimStyle,
60+
ProgressHintDelegate.DEFAULT_HINT_ADAPTER);
6361
}
6462

6563
public ProgressHintDelegate(SeekBar seekBar, AttributeSet attrs, int defStyleAttr) {
66-
TypedArray a = seekBar.getContext()
67-
.obtainStyledAttributes(attrs, R.styleable.ProgressHint, defStyleAttr,
68-
R.style.Widget_ProgressHint);
64+
TypedArray a = seekBar.getContext().obtainStyledAttributes(attrs, R.styleable.ProgressHint, defStyleAttr, R.style.Widget_ProgressHint);
6965
//
70-
int mPopupLayout =
71-
a.getResourceId(R.styleable.ProgressHint_popupLayout, R.layout.progress_hint_popup);
66+
int mPopupLayout = a.getResourceId(R.styleable.ProgressHint_popupLayout, R.layout.progress_hint_popup);
7267
int mPopupOffset = (int) a.getDimension(R.styleable.ProgressHint_popupOffset, 0);
73-
int mPopupStyle =
74-
a.getInt(R.styleable.ProgressHint_popupStyle, ProgressHintDelegate.POPUP_FOLLOW);
75-
int mPopupAnimStyle = a.getResourceId(R.styleable.ProgressHint_popupAnimationStyle,
76-
R.style.ProgressHintPopupAnimation);
68+
int mPopupStyle = a.getInt(R.styleable.ProgressHint_popupStyle, ProgressHintDelegate.POPUP_FOLLOW);
69+
int mPopupAnimStyle = a.getResourceId(R.styleable.ProgressHint_popupAnimationStyle, R.style.ProgressHintPopupAnimation);
7770
boolean mPopupAlwaysShown = a.getBoolean(R.styleable.ProgressHint_popupAlwaysShown, false);
7871
boolean mPopupDraggable = a.getBoolean(R.styleable.ProgressHint_popupDraggable, false);
7972
a.recycle();
8073
//
81-
initDelegate(seekBar, mPopupLayout, mPopupOffset, mPopupAlwaysShown, mPopupDraggable,
82-
mPopupStyle, mPopupAnimStyle, ProgressHintDelegate.DEFAULT_HINT_ADAPTER);
74+
initDelegate(seekBar, mPopupLayout, mPopupOffset, mPopupAlwaysShown, mPopupDraggable, mPopupStyle, mPopupAnimStyle,
75+
ProgressHintDelegate.DEFAULT_HINT_ADAPTER);
8376
}
8477

85-
private void initDelegate(SeekBar seekBar, int mPopupLayout, int mPopupOffset,
86-
boolean mPopupAlwaysShown, boolean mPopupDraggable, int mPopupStyle, int mPopupAnimStyle,
87-
SeekBarHintAdapter mHintAdapter) {
78+
private void initDelegate(SeekBar seekBar, int mPopupLayout, int mPopupOffset, boolean mPopupAlwaysShown, boolean mPopupDraggable,
79+
int mPopupStyle, int mPopupAnimStyle, SeekBarHintAdapter mHintAdapter) {
8880
this.mSeekBar = seekBar;
8981
this.mPopupLayout = mPopupLayout;
9082
this.mPopupOffset = mPopupOffset;
@@ -105,8 +97,7 @@ private void initHintPopup() {
10597
}
10698

10799
// init views
108-
LayoutInflater inflater =
109-
(LayoutInflater) mSeekBar.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
100+
LayoutInflater inflater = (LayoutInflater) mSeekBar.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
110101
mPopupView = inflater.inflate(mPopupLayout, null);
111102
mPopupView.measure(makeMeasureSpec(0, UNSPECIFIED), makeMeasureSpec(0, UNSPECIFIED));
112103
mPopupTextView = (TextView) mPopupView.findViewById(android.R.id.text1);
@@ -150,8 +141,8 @@ private void checkInitialState() {
150141
private OnTouchListener popupTouchProxy = new OnTouchListener() {
151142
@Override public boolean onTouch(View v, MotionEvent event) {
152143
PointF coordinates = getHintDragCoordinates(event);
153-
event = MotionEvent.obtain(event.getDownTime(), event.getEventTime(), event.getAction(),
154-
coordinates.x, coordinates.y, event.getMetaState());
144+
event = MotionEvent
145+
.obtain(event.getDownTime(), event.getEventTime(), event.getAction(), coordinates.x, coordinates.y, event.getMetaState());
155146
return mSeekBar.dispatchTouchEvent(event);
156147
}
157148
};
@@ -217,7 +208,10 @@ public void setPopupAlwaysShown(boolean alwaysShown) {
217208
this.mPopupAlwaysShown = alwaysShown;
218209
if (alwaysShown) {
219210
showPopup();
220-
} else if (!isTracking) hidePopup();
211+
listener.onProgressChanged(mSeekBar, mSeekBar.getProgress(), false);
212+
} else if (!isTracking) {
213+
hidePopup();
214+
}
221215
}
222216

223217
public boolean isPopupDraggable() {
@@ -318,9 +312,7 @@ protected int getFollowPosition() {
318312
}
319313

320314
protected int getFollowPosition(int progress) {
321-
return (int) (progress * (mSeekBar.getWidth()
322-
- mSeekBar.getPaddingLeft()
323-
- mSeekBar.getPaddingRight()) / (float) mSeekBar.getMax());
315+
return (int) (progress * (mSeekBar.getWidth() - mSeekBar.getPaddingLeft() - mSeekBar.getPaddingRight()) / (float) mSeekBar.getMax());
324316
}
325317

326318
///////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)