Use material slider in SeekBarDialog

pull/437/head
Alex Baker 8 years ago
parent d5fb5452f3
commit b1671e74fa

@ -121,6 +121,7 @@ dependencies {
debugCompile "com.facebook.stetho:stetho-timber:${STETHO_VERSION}@aar" debugCompile "com.facebook.stetho:stetho-timber:${STETHO_VERSION}@aar"
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2' debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2'
compile 'com.github.rey5137:material:1.2.4'
compile 'com.android.support:multidex:1.0.1' compile 'com.android.support:multidex:1.0.1'
compile 'com.nononsenseapps:filepicker:2.5.2' compile 'com.nononsenseapps:filepicker:2.5.2'
compile "com.android.support:design:${SUPPORT_VERSION}" compile "com.android.support:design:${SUPPORT_VERSION}"

@ -4,13 +4,12 @@ import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.icu.text.NumberFormat;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView; import com.rey.material.widget.Slider;
import org.tasks.R; import org.tasks.R;
import org.tasks.injection.DialogFragmentComponent; import org.tasks.injection.DialogFragmentComponent;
@ -24,56 +23,48 @@ import butterknife.ButterKnife;
public class SeekBarDialog extends InjectingDialogFragment { public class SeekBarDialog extends InjectingDialogFragment {
private static final String EXTRA_MIN_VALUE = "extra_min_value"; private static final String EXTRA_LAYOUT = "extra_layout";
private static final String EXTRA_MAX_VALUE = "extra_max_value";
private static final String EXTRA_INITIAL_VALUE = "extra_initial_value"; private static final String EXTRA_INITIAL_VALUE = "extra_initial_value";
public static final String EXTRA_VALUE = "extra_value"; public static final String EXTRA_VALUE = "extra_value";
public static SeekBarDialog newSeekBarDialog(int minValue, int maxValue, int initial) { public static SeekBarDialog newSeekBarDialog(int layout, int initial) {
SeekBarDialog dialog = new SeekBarDialog(); SeekBarDialog dialog = new SeekBarDialog();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putInt(EXTRA_MIN_VALUE, minValue); args.putInt(EXTRA_LAYOUT, layout);
args.putInt(EXTRA_MAX_VALUE, maxValue);
dialog.setArguments(args); dialog.setArguments(args);
dialog.initial = initial; dialog.initial = initial;
return dialog; return dialog;
} }
@BindView(R.id.seekbar) SeekBar seekBar; @BindView(R.id.slider) Slider slider;
@BindView(R.id.min) TextView min;
@BindView(R.id.max) TextView max;
@Inject DialogBuilder dialogBuilder; @Inject DialogBuilder dialogBuilder;
@Inject Theme theme; @Inject Theme theme;
private int minValue;
private int maxValue;
private int initial; private int initial;
@NonNull @NonNull
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater layoutInflater = theme.getLayoutInflater(getContext());
View view = layoutInflater.inflate(R.layout.dialog_seekbar, null);
ButterKnife.bind(this, view);
Bundle arguments = getArguments(); Bundle arguments = getArguments();
if (savedInstanceState != null) { if (savedInstanceState != null) {
initial = savedInstanceState.getInt(EXTRA_INITIAL_VALUE); initial = savedInstanceState.getInt(EXTRA_INITIAL_VALUE);
} }
minValue = arguments.getInt(EXTRA_MIN_VALUE); int layout = arguments.getInt(EXTRA_LAYOUT);
maxValue = arguments.getInt(EXTRA_MAX_VALUE);
min.setText(NumberFormat.getIntegerInstance().format(minValue)); LayoutInflater layoutInflater = theme.getLayoutInflater(getContext());
max.setText(NumberFormat.getIntegerInstance().format(maxValue)); View view = layoutInflater.inflate(layout, null);
seekBar.setMax(maxValue - minValue); ButterKnife.bind(this, view);
seekBar.setProgress(initial);
slider.setValue(initial, true);
return dialogBuilder.newDialog() return dialogBuilder.newDialog()
.setView(view) .setView(view)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, new Intent() {{ getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, new Intent() {{
putExtra(EXTRA_VALUE, seekBar.getProgress() + minValue); putExtra(EXTRA_VALUE, slider.getValue());
}}); }});
} }
}) })
@ -85,7 +76,7 @@ public class SeekBarDialog extends InjectingDialogFragment {
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
outState.putInt(EXTRA_INITIAL_VALUE, seekBar.getProgress()); outState.putInt(EXTRA_INITIAL_VALUE, slider.getValue());
} }
@Override @Override

@ -182,7 +182,7 @@ public class WidgetConfigDialog extends InjectingDialogFragment {
@OnClick(R.id.widget_opacity) @OnClick(R.id.widget_opacity)
public void showOpacitySlider() { public void showOpacitySlider() {
SeekBarDialog seekBarDialog = newSeekBarDialog(0, 100, opacityPercentage); SeekBarDialog seekBarDialog = newSeekBarDialog(R.layout.dialog_opacity_seekbar, opacityPercentage);
seekBarDialog.setTargetFragment(this, REQUEST_OPACITY); seekBarDialog.setTargetFragment(this, REQUEST_OPACITY);
seekBarDialog.show(getChildFragmentManager(), FRAG_TAG_SEEKBAR); seekBarDialog.show(getChildFragmentManager(), FRAG_TAG_SEEKBAR);
} }

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.rey.material.widget.Slider xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/slider"
style="@style/Material.Widget.Slider.Discrete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:minHeight="?attr/listPreferredItemHeight"
android:paddingEnd="@dimen/keyline_first"
android:paddingLeft="@dimen/keyline_first"
android:paddingRight="@dimen/keyline_first"
android:paddingStart="@dimen/keyline_first"
app:sl_discreteMode="true"
app:sl_maxValue="100"
app:sl_minValue="0"
app:sl_stepValue="5"
app:sl_travelAnimDuration="50" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@id/slider"
android:paddingEnd="@dimen/keyline_first"
android:paddingLeft="@dimen/keyline_first"
android:paddingRight="@dimen/keyline_first"
android:paddingStart="@dimen/keyline_first"
android:paddingTop="5dp"
android:text="0" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@id/slider"
android:paddingEnd="@dimen/keyline_first"
android:paddingLeft="@dimen/keyline_first"
android:paddingRight="@dimen/keyline_first"
android:paddingStart="@dimen/keyline_first"
android:paddingTop="5dp"
android:text="100" />
</RelativeLayout>

@ -1,38 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="?attr/listPreferredItemHeight"
android:paddingBottom="@dimen/keyline_first"
android:paddingTop="@dimen/keyline_first">
<TextView
android:id="@+id/min"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:paddingLeft="@dimen/keyline_first"
android:paddingStart="@dimen/keyline_first" />
<TextView
android:id="@+id/max"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:paddingEnd="@dimen/keyline_first"
android:paddingRight="@dimen/keyline_first" />
<SeekBar
android:id="@+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/min"
android:layout_toLeftOf="@id/max"
android:layout_toRightOf="@id/min"
android:layout_toStartOf="@id/max"
android:indeterminate="false" />
</RelativeLayout>
Loading…
Cancel
Save