Merge 'fdroidclient-seekbar3' into 'master'
* ByteHamster/fdroidclient-seekbar3: fix pmd "Overriding method merely calls super" Code style improvements Explain null value Make checkstyle happy Display disabled state Updated seekbar appearance fdroid/fdroidclient!693
This commit is contained in:
		
						commit
						40d80bd41f
					
				| @ -37,7 +37,7 @@ public class LiveSeekBarPreference extends SeekBarPreference { | ||||
|     public void onBindViewHolder(final PreferenceViewHolder holder) { | ||||
|         super.onBindViewHolder(holder); | ||||
| 
 | ||||
|         SeekBar seekbar = holder.itemView.findViewById(R.id.seekbar); | ||||
|         SeekBarForegroundThumb seekbar = holder.itemView.findViewById(R.id.seekbar); | ||||
|         seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { | ||||
|             @Override | ||||
|             public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { | ||||
| @ -66,6 +66,12 @@ public class LiveSeekBarPreference extends SeekBarPreference { | ||||
|             } | ||||
|         }); | ||||
|         seekbar.setProgress(value); | ||||
| 
 | ||||
|         if (isEnabled()) { | ||||
|             seekbar.setAlpha(1.0f); | ||||
|         } else { | ||||
|             seekbar.setAlpha(0.3f); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|  | ||||
| @ -0,0 +1,82 @@ | ||||
| package org.fdroid.fdroid.views; | ||||
| 
 | ||||
| import android.content.Context; | ||||
| import android.graphics.Canvas; | ||||
| import android.graphics.drawable.Drawable; | ||||
| import android.os.Build; | ||||
| import android.support.v7.widget.AppCompatSeekBar; | ||||
| import android.util.AttributeSet; | ||||
| import org.fdroid.fdroid.R; | ||||
| 
 | ||||
| /** | ||||
|  * SeekBar that does not show the TickMark above the thumb | ||||
|  * Based on https://stackoverflow.com/a/47727128 | ||||
|  */ | ||||
| public class SeekBarForegroundThumb extends AppCompatSeekBar { | ||||
|     private Drawable tickMark; | ||||
|     private Context context; | ||||
| 
 | ||||
|     public SeekBarForegroundThumb(Context context) { | ||||
|         super(context); | ||||
|         init(context); | ||||
|     } | ||||
| 
 | ||||
|     public SeekBarForegroundThumb(Context context, AttributeSet attrs) { | ||||
|         super(context, attrs); | ||||
|         init(context); | ||||
|     } | ||||
| 
 | ||||
|     public SeekBarForegroundThumb(Context context, AttributeSet attrs, int defStyleAttr) { | ||||
|         super(context, attrs, defStyleAttr); | ||||
|         init(context); | ||||
|     } | ||||
| 
 | ||||
|     private void init(Context context) { | ||||
|         this.context = context; | ||||
| 
 | ||||
|         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||||
|             tickMark = context.getDrawable(R.drawable.seekbar_tickmark); | ||||
|         } else { | ||||
|             tickMark = context.getResources().getDrawable(R.drawable.seekbar_tickmark); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private Drawable getThumbCompat() { | ||||
|         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { | ||||
|             return getThumb(); | ||||
|         } else { | ||||
|             return context.getResources().getDrawable(R.drawable.seekbar_thumb); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     protected synchronized void onDraw(Canvas canvas) { | ||||
|         super.onDraw(canvas); | ||||
|         drawTickMarks(canvas); | ||||
|     } | ||||
| 
 | ||||
|     private void drawTickMarks(Canvas canvas) { | ||||
|         if (tickMark != null) { | ||||
|             final int count = getMax(); | ||||
|             if (count > 1) { | ||||
|                 final int w = tickMark.getIntrinsicWidth(); | ||||
|                 final int h = tickMark.getIntrinsicHeight(); | ||||
|                 final int halfThumbW = getThumbCompat().getIntrinsicWidth() / 2; | ||||
|                 final int halfW = w >= 0 ? w / 2 : 1; | ||||
|                 final int halfH = h >= 0 ? h / 2 : 1; | ||||
|                 tickMark.setBounds(-halfW, -halfH, halfW, halfH); | ||||
|                 final float spacing = (getWidth() - getPaddingLeft() - getPaddingRight() | ||||
|                         + getThumbOffset() * 2 - halfThumbW * 2) / (float) count; | ||||
|                 final int saveCount = canvas.save(); | ||||
|                 canvas.translate(getPaddingLeft() - getThumbOffset() + halfThumbW, getHeight() / 2); | ||||
|                 for (int i = 0; i <= count; i++) { | ||||
|                     if (i != getProgress()) { | ||||
|                         tickMark.draw(canvas); | ||||
|                     } | ||||
|                     canvas.translate(spacing, 0); | ||||
|                 } | ||||
|                 canvas.restoreToCount(saveCount); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
										
											Binary file not shown.
										
									
								
							| Before Width: | Height: | Size: 206 B | 
| @ -1,12 +0,0 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > | ||||
|     <item android:id="@android:id/background"> | ||||
|         <nine-patch android:src="@drawable/seekbar_bg" android:dither="true"/> | ||||
|     </item> | ||||
|     <item android:id="@android:id/progress"> | ||||
|         <clip android:clipOrientation="horizontal" | ||||
|               android:gravity="left"> | ||||
|             <nine-patch android:src="@drawable/seekbar_fill" android:dither="true"/> | ||||
|         </clip> | ||||
|     </item> | ||||
| </layer-list> | ||||
| @ -2,10 +2,10 @@ | ||||
| <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | ||||
|     <item> | ||||
|         <shape android:shape="oval"> | ||||
|             <solid android:color="@color/fdroid_green"/> | ||||
|             <solid android:color="#818181"/> | ||||
|             <size | ||||
|                     android:width="10dp" | ||||
|                     android:height="10dp"/> | ||||
|                     android:width="6dp" | ||||
|                     android:height="6dp"/> | ||||
|         </shape> | ||||
|     </item> | ||||
| </layer-list> | ||||
| @ -39,14 +39,14 @@ | ||||
|             android:visibility="gone" | ||||
|             android:textSize="0sp"/> | ||||
| 
 | ||||
|     <SeekBar xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     <org.fdroid.fdroid.views.SeekBarForegroundThumb | ||||
|              android:id="@+id/seekbar" | ||||
|              android:layout_width="match_parent" | ||||
|              android:layout_height="wrap_content" | ||||
|              android:layout_below="@android:id/summary" | ||||
|              android:layout_alignStart="@android:id/summary" | ||||
|              android:layout_alignLeft="@android:id/summary" | ||||
|              android:progressDrawable="@drawable/seekbar_progress" | ||||
|              android:progressDrawable="@drawable/seekbar_bg" | ||||
|              android:thumb="@drawable/seekbar_thumb" | ||||
|              android:padding="16dip" | ||||
|              android:theme="@style/DiscreteSeekBar"/> | ||||
|  | ||||
| @ -319,6 +319,6 @@ | ||||
|     <style name="AppThemeLight.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/> | ||||
| 
 | ||||
|     <style name="DiscreteSeekBar" parent="Base.Widget.AppCompat.SeekBar.Discrete"> | ||||
|         <item name="tickMark">@drawable/seekbar_tickmark</item> | ||||
|         <item name="tickMark">@null</item> <!-- Disable default tickMarks. We draw our own in SeekBarForegroundThumb --> | ||||
|     </style> | ||||
| </resources> | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Hans-Christoph Steiner
						Hans-Christoph Steiner