@@ -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