Updated seekbar appearance
This commit is contained in:
parent
a8af84ecbc
commit
1f4b6e483a
@ -37,7 +37,7 @@ public class LiveSeekBarPreference extends SeekBarPreference {
|
|||||||
public void onBindViewHolder(final PreferenceViewHolder holder) {
|
public void onBindViewHolder(final PreferenceViewHolder holder) {
|
||||||
super.onBindViewHolder(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() {
|
seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||||
|
@ -0,0 +1,85 @@
|
|||||||
|
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 mTickMark;
|
||||||
|
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) {
|
||||||
|
mTickMark = context.getDrawable(R.drawable.seekbar_tickmark);
|
||||||
|
} else {
|
||||||
|
mTickMark = 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getThumbOffset() {
|
||||||
|
return super.getThumbOffset();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawTickMarks(Canvas canvas) {
|
||||||
|
if (mTickMark != null) {
|
||||||
|
final int count = getMax();
|
||||||
|
if (count > 1) {
|
||||||
|
final int w = mTickMark.getIntrinsicWidth();
|
||||||
|
final int h = mTickMark.getIntrinsicHeight();
|
||||||
|
final int halfThumbW = getThumbCompat().getIntrinsicWidth() / 2;
|
||||||
|
final int halfW = w >= 0 ? w / 2 : 1;
|
||||||
|
final int halfH = h >= 0 ? h / 2 : 1;
|
||||||
|
mTickMark.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())
|
||||||
|
mTickMark.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">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item>
|
<item>
|
||||||
<shape android:shape="oval">
|
<shape android:shape="oval">
|
||||||
<solid android:color="@color/fdroid_green"/>
|
<solid android:color="#818181"/>
|
||||||
<size
|
<size
|
||||||
android:width="10dp"
|
android:width="6dp"
|
||||||
android:height="10dp"/>
|
android:height="6dp"/>
|
||||||
</shape>
|
</shape>
|
||||||
</item>
|
</item>
|
||||||
</layer-list>
|
</layer-list>
|
@ -39,14 +39,14 @@
|
|||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
android:textSize="0sp"/>
|
android:textSize="0sp"/>
|
||||||
|
|
||||||
<SeekBar xmlns:android="http://schemas.android.com/apk/res/android"
|
<org.fdroid.fdroid.views.SeekBarForegroundThumb
|
||||||
android:id="@+id/seekbar"
|
android:id="@+id/seekbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@android:id/summary"
|
android:layout_below="@android:id/summary"
|
||||||
android:layout_alignStart="@android:id/summary"
|
android:layout_alignStart="@android:id/summary"
|
||||||
android:layout_alignLeft="@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:thumb="@drawable/seekbar_thumb"
|
||||||
android:padding="16dip"
|
android:padding="16dip"
|
||||||
android:theme="@style/DiscreteSeekBar"/>
|
android:theme="@style/DiscreteSeekBar"/>
|
||||||
|
@ -319,6 +319,6 @@
|
|||||||
<style name="AppThemeLight.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
|
<style name="AppThemeLight.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
|
||||||
|
|
||||||
<style name="DiscreteSeekBar" parent="Base.Widget.AppCompat.SeekBar.Discrete">
|
<style name="DiscreteSeekBar" parent="Base.Widget.AppCompat.SeekBar.Discrete">
|
||||||
<item name="tickMark">@drawable/seekbar_tickmark</item>
|
<item name="tickMark">@null</item>
|
||||||
</style>
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user