|
|
@ -24,6 +24,7 @@ import android.content.*;
|
|
|
|
import android.net.*;
|
|
|
|
import android.net.*;
|
|
|
|
import android.support.annotation.*;
|
|
|
|
import android.support.annotation.*;
|
|
|
|
import android.support.v7.app.AlertDialog;
|
|
|
|
import android.support.v7.app.AlertDialog;
|
|
|
|
|
|
|
|
import android.text.*;
|
|
|
|
import android.view.*;
|
|
|
|
import android.view.*;
|
|
|
|
import android.widget.*;
|
|
|
|
import android.widget.*;
|
|
|
|
|
|
|
|
|
|
|
@ -39,6 +40,7 @@ import org.isoron.uhabits.models.*;
|
|
|
|
import org.isoron.uhabits.utils.*;
|
|
|
|
import org.isoron.uhabits.utils.*;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
import java.io.*;
|
|
|
|
|
|
|
|
import java.lang.reflect.*;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.inject.*;
|
|
|
|
import javax.inject.*;
|
|
|
|
|
|
|
|
|
|
|
@ -46,7 +48,6 @@ import static android.content.DialogInterface.*;
|
|
|
|
import static android.os.Build.VERSION.*;
|
|
|
|
import static android.os.Build.VERSION.*;
|
|
|
|
import static android.os.Build.VERSION_CODES.*;
|
|
|
|
import static android.os.Build.VERSION_CODES.*;
|
|
|
|
import static android.view.inputmethod.EditorInfo.*;
|
|
|
|
import static android.view.inputmethod.EditorInfo.*;
|
|
|
|
import static org.isoron.uhabits.utils.InterfaceUtils.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ActivityScope
|
|
|
|
@ActivityScope
|
|
|
|
public class ListHabitsScreen extends BaseScreen
|
|
|
|
public class ListHabitsScreen extends BaseScreen
|
|
|
@ -287,27 +288,44 @@ public class ListHabitsScreen extends BaseScreen
|
|
|
|
activity.startActivity(intent);
|
|
|
|
activity.startActivity(intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void showNumberPicker(int initialValue,
|
|
|
|
public void showNumberPicker(double value,
|
|
|
|
|
|
|
|
@NonNull String unit,
|
|
|
|
@NonNull NumberPickerCallback callback)
|
|
|
|
@NonNull NumberPickerCallback callback)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LayoutInflater inflater = activity.getLayoutInflater();
|
|
|
|
LayoutInflater inflater = activity.getLayoutInflater();
|
|
|
|
View view = inflater.inflate(R.layout.number_picker_dialog, null);
|
|
|
|
View view = inflater.inflate(R.layout.number_picker_dialog, null);
|
|
|
|
|
|
|
|
|
|
|
|
final NumberPicker picker =
|
|
|
|
final NumberPicker picker;
|
|
|
|
(NumberPicker) view.findViewById(R.id.picker);
|
|
|
|
final NumberPicker picker2;
|
|
|
|
|
|
|
|
final TextView tvUnit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
picker = (NumberPicker) view.findViewById(R.id.picker);
|
|
|
|
|
|
|
|
picker2 = (NumberPicker) view.findViewById(R.id.picker2);
|
|
|
|
|
|
|
|
tvUnit = (TextView) view.findViewById(R.id.tvUnit);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int intValue = (int) Math.round(value * 100);
|
|
|
|
|
|
|
|
|
|
|
|
picker.setMinValue(0);
|
|
|
|
picker.setMinValue(0);
|
|
|
|
picker.setMaxValue(Integer.MAX_VALUE);
|
|
|
|
picker.setMaxValue(Integer.MAX_VALUE / 100);
|
|
|
|
picker.setValue(initialValue);
|
|
|
|
picker.setValue(intValue / 100);
|
|
|
|
picker.setWrapSelectorWheel(false);
|
|
|
|
picker.setWrapSelectorWheel(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
picker2.setMinValue(0);
|
|
|
|
|
|
|
|
picker2.setMaxValue(19);
|
|
|
|
|
|
|
|
picker2.setFormatter(v -> String.format("%02d", 5 * v));
|
|
|
|
|
|
|
|
picker2.setValue((intValue % 100) / 5);
|
|
|
|
|
|
|
|
refreshInitialValue(picker2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tvUnit.setText(unit);
|
|
|
|
|
|
|
|
|
|
|
|
AlertDialog dialog = new AlertDialog.Builder(activity)
|
|
|
|
AlertDialog dialog = new AlertDialog.Builder(activity)
|
|
|
|
.setView(view)
|
|
|
|
.setView(view)
|
|
|
|
.setTitle(R.string.change_value)
|
|
|
|
.setTitle(R.string.change_value)
|
|
|
|
.setPositiveButton(android.R.string.ok, (d, which) ->
|
|
|
|
.setPositiveButton(android.R.string.ok, (d, which) ->
|
|
|
|
{
|
|
|
|
{
|
|
|
|
picker.clearFocus();
|
|
|
|
picker.clearFocus();
|
|
|
|
callback.onNumberPicked(picker.getValue());
|
|
|
|
double v = picker.getValue() + 0.05 * picker2.getValue();
|
|
|
|
|
|
|
|
callback.onNumberPicked(v);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.create();
|
|
|
|
.create();
|
|
|
|
|
|
|
|
|
|
|
@ -319,13 +337,22 @@ public class ListHabitsScreen extends BaseScreen
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
dialog.show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Window window = dialog.getWindow();
|
|
|
|
private void refreshInitialValue(NumberPicker picker2)
|
|
|
|
if (window != null)
|
|
|
|
{
|
|
|
|
|
|
|
|
// Workaround for a bug on Android:
|
|
|
|
|
|
|
|
// https://code.google.com/p/android/issues/detail?id=35482
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Field f = NumberPicker.class.getDeclaredField("mInputText");
|
|
|
|
|
|
|
|
f.setAccessible(true);
|
|
|
|
|
|
|
|
EditText inputText = (EditText) f.get(picker2);
|
|
|
|
|
|
|
|
inputText.setFilters(new InputFilter[0]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int width = (int) dpToPixels(activity, 200);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
int height = (int) dpToPixels(activity, 275);
|
|
|
|
|
|
|
|
window.setLayout(width, height);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -395,6 +422,6 @@ public class ListHabitsScreen extends BaseScreen
|
|
|
|
|
|
|
|
|
|
|
|
public interface NumberPickerCallback
|
|
|
|
public interface NumberPickerCallback
|
|
|
|
{
|
|
|
|
{
|
|
|
|
void onNumberPicked(int newValue);
|
|
|
|
void onNumberPicked(double newValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|