Provide default parameter names
This commit is contained in:
parent
c437c2d0c9
commit
b03a0df74e
@ -1,15 +1,21 @@
|
||||
package org.solovyev.android.calculator.plot;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.functions.CppFunction;
|
||||
import org.solovyev.android.calculator.functions.FunctionParamsView;
|
||||
|
||||
import static android.support.test.espresso.Espresso.onView;
|
||||
import static android.support.test.espresso.action.ViewActions.click;
|
||||
import static android.support.test.espresso.action.ViewActions.typeTextIntoFocusedView;
|
||||
import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.hasFocus;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withTagValue;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withText;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
public class PlotEditFunctionFragmentTest extends BasePlotTest {
|
||||
@ -35,4 +41,22 @@ public class PlotEditFunctionFragmentTest extends BasePlotTest {
|
||||
|
||||
onView(withId(R.id.function_params_add)).check(matches(not(isDisplayed())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldProvideDefaultParamNames() throws Exception {
|
||||
openFunctionEditor();
|
||||
|
||||
onView(withId(R.id.function_params_add)).perform(click());
|
||||
onView(allOf(hasFocus(), withTagValue(Matchers.<Object>equalTo(FunctionParamsView.PARAM_VIEW_TAG)))).check(matches(withText("x")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldSelectParamOnFocus() throws Exception {
|
||||
openFunctionEditor();
|
||||
|
||||
onView(withId(R.id.function_params_add)).perform(click());
|
||||
// check "select-on-focus" attribute
|
||||
onView(allOf(hasFocus(), withTagValue(Matchers.<Object>equalTo(FunctionParamsView.PARAM_VIEW_TAG)))).perform(typeTextIntoFocusedView("y"));
|
||||
onView(allOf(hasFocus(), withTagValue(Matchers.<Object>equalTo(FunctionParamsView.PARAM_VIEW_TAG)))).check(matches(withText("y")));
|
||||
}
|
||||
}
|
@ -48,6 +48,7 @@ import org.solovyev.android.calculator.Preferences;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -60,6 +61,7 @@ public class FunctionParamsView extends LinearLayout {
|
||||
|
||||
@Nonnull
|
||||
public static final String PARAM_VIEW_TAG = "param-view";
|
||||
private static final List<String> PARAM_NAMES = Arrays.asList("x", "y", "z", "t", "a", "b", "c");
|
||||
private static final int FOOTERS = 1;
|
||||
private static final int PARAM_VIEW_INDEX = 3;
|
||||
private static final int START_ROW_ID = App.generateViewId();
|
||||
@ -106,7 +108,7 @@ public class FunctionParamsView extends LinearLayout {
|
||||
addButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final LinearLayout rowView = addParam(null);
|
||||
final LinearLayout rowView = addParam(generateParamName());
|
||||
final EditText paramView = getParamView(rowView);
|
||||
paramView.requestFocus();
|
||||
}
|
||||
@ -116,6 +118,13 @@ public class FunctionParamsView extends LinearLayout {
|
||||
addView(headerView, new ViewGroup.LayoutParams(MATCH_PARENT, WRAP_CONTENT));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String generateParamName() {
|
||||
final List<String> available = new ArrayList<>(PARAM_NAMES);
|
||||
available.removeAll(getParams());
|
||||
return available.size() > 0 ? available.get(0) : null;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private ImageButton makeButton(int icon) {
|
||||
final ImageButton addButton = new ImageButton(getContext());
|
||||
@ -187,6 +196,7 @@ public class FunctionParamsView extends LinearLayout {
|
||||
paramView.setText(param);
|
||||
}
|
||||
paramView.setOnFocusChangeListener(getOnFocusChangeListener());
|
||||
paramView.setSelectAllOnFocus(true);
|
||||
paramView.setInputType(EditorInfo.TYPE_CLASS_TEXT);
|
||||
paramView.setId(id);
|
||||
paramView.setTag(PARAM_VIEW_TAG);
|
||||
|
Loading…
Reference in New Issue
Block a user