Use number picker for default snooze time

This commit is contained in:
M66B 2019-10-12 15:59:18 +02:00
parent 2d4eb2b96b
commit ca670c6732
2 changed files with 19 additions and 33 deletions

View File

@ -25,8 +25,6 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Paint; import android.graphics.Paint;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
@ -36,7 +34,7 @@ import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.Button; import android.widget.Button;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.NumberPicker;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -50,7 +48,7 @@ import androidx.preference.PreferenceManager;
public class FragmentOptionsMisc extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener { public class FragmentOptionsMisc extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
private SwitchCompat swDoubleBack; private SwitchCompat swDoubleBack;
private EditText etDefaultSnooze; private NumberPicker npDefaultSnooze;
private Spinner spBiometricsTimeout; private Spinner spBiometricsTimeout;
private SwitchCompat swEnglish; private SwitchCompat swEnglish;
private SwitchCompat swWatchdog; private SwitchCompat swWatchdog;
@ -90,7 +88,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
// Get controls // Get controls
swDoubleBack = view.findViewById(R.id.swDoubleBack); swDoubleBack = view.findViewById(R.id.swDoubleBack);
etDefaultSnooze = view.findViewById(R.id.etDefaultSnooze); npDefaultSnooze = view.findViewById(R.id.npDefaultSnooze);
spBiometricsTimeout = view.findViewById(R.id.spBiometricsTimeout); spBiometricsTimeout = view.findViewById(R.id.spBiometricsTimeout);
swEnglish = view.findViewById(R.id.swEnglish); swEnglish = view.findViewById(R.id.swEnglish);
swWatchdog = view.findViewById(R.id.swWatchdog); swWatchdog = view.findViewById(R.id.swWatchdog);
@ -109,6 +107,9 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
grpDebug = view.findViewById(R.id.grpDebug); grpDebug = view.findViewById(R.id.grpDebug);
npDefaultSnooze.setMinValue(1);
npDefaultSnooze.setMaxValue(999);
setOptions(); setOptions();
// Wire controls // Wire controls
@ -122,22 +123,10 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
} }
}); });
etDefaultSnooze.addTextChangedListener(new TextWatcher() { npDefaultSnooze.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
} prefs.edit().putInt("default_snooze", newVal).apply();
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable editable) {
try {
int hours = Integer.parseInt(editable.toString());
prefs.edit().putInt("default_snooze", hours).apply();
} catch (NumberFormatException ignored) {
}
} }
}); });
@ -326,7 +315,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
swDoubleBack.setChecked(prefs.getBoolean("double_back", true)); swDoubleBack.setChecked(prefs.getBoolean("double_back", true));
etDefaultSnooze.setText(Integer.toString(prefs.getInt("default_snooze", 1))); npDefaultSnooze.setValue(prefs.getInt("default_snooze", 1));
int biometrics_timeout = prefs.getInt("biometrics_timeout", 2); int biometrics_timeout = prefs.getInt("biometrics_timeout", 2);
int[] biometricTimeoutValues = getResources().getIntArray(R.array.biometricsTimeoutValues); int[] biometricTimeoutValues = getResources().getIntArray(R.array.biometricsTimeoutValues);

View File

@ -36,25 +36,22 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swDoubleBack" /> app:layout_constraintTop_toBottomOf="@id/swDoubleBack" />
<EditText <NumberPicker
android:id="@+id/etDefaultSnooze" android:id="@+id/npDefaultSnooze"
android:layout_width="60dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="end"
android:inputType="number"
android:text="1"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDefaultSnooze" /> app:layout_constraintTop_toBottomOf="@+id/tvDefaultSnooze" />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="6dp" android:layout_marginStart="12dp"
android:text="@string/title_hours" android:text="@string/title_hours"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toBottomOf="@+id/etDefaultSnooze" app:layout_constraintBottom_toBottomOf="@+id/npDefaultSnooze"
app:layout_constraintStart_toEndOf="@+id/etDefaultSnooze" app:layout_constraintStart_toEndOf="@+id/npDefaultSnooze"
app:layout_constraintTop_toTopOf="@+id/etDefaultSnooze" /> app:layout_constraintTop_toTopOf="@+id/npDefaultSnooze" />
<TextView <TextView
android:id="@+id/tvBiometricsTimeout" android:id="@+id/tvBiometricsTimeout"
@ -67,7 +64,7 @@
android:textColor="?android:attr/textColorPrimary" android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etDefaultSnooze" /> app:layout_constraintTop_toBottomOf="@id/npDefaultSnooze" />
<Spinner <Spinner
android:id="@+id/spBiometricsTimeout" android:id="@+id/spBiometricsTimeout"