diff --git a/app/src/main/java/com/google/android/apps/flexbox/FlexItemEditFragment.java b/app/src/main/java/com/google/android/apps/flexbox/FlexItemEditFragment.java index 84588a0b34aa2f934b4ee0665f4af51768baba19..b56265cecca9d4794565b99f553903d6348aa0a8 100644 --- a/app/src/main/java/com/google/android/apps/flexbox/FlexItemEditFragment.java +++ b/app/src/main/java/com/google/android/apps/flexbox/FlexItemEditFragment.java @@ -16,15 +16,16 @@ package com.google.android.apps.flexbox; +import com.google.android.apps.flexbox.validators.DimensionInputValidator; import com.google.android.apps.flexbox.validators.FixedDimensionInputValidator; import com.google.android.apps.flexbox.validators.FlexBasisPercentInputValidator; import com.google.android.apps.flexbox.validators.InputValidator; import com.google.android.apps.flexbox.validators.IntegerInputValidator; import com.google.android.apps.flexbox.validators.NonNegativeDecimalInputValidator; -import com.google.android.apps.flexbox.validators.DimensionInputValidator; import com.google.android.flexbox.FlexboxLayout; import android.app.Activity; +import android.content.Context; import android.os.Build; import android.os.Bundle; import android.support.annotation.Nullable; @@ -33,14 +34,18 @@ import android.support.v4.app.DialogFragment; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; +import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodManager; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.Spinner; +import android.widget.TextView; import android.widget.Toast; /** @@ -111,7 +116,7 @@ public class FlexItemEditFragment extends DialogFragment { final TextInputLayout flexGrowInput = (TextInputLayout) view .findViewById(R.id.input_layout_flex_grow); - EditText flexGrowEdit = (EditText) view.findViewById(R.id.edit_text_flex_grow); + final EditText flexGrowEdit = (EditText) view.findViewById(R.id.edit_text_flex_grow); flexGrowEdit.setText(String.valueOf(mFlexItem.flexGrow)); flexGrowEdit.addTextChangedListener( new FlexEditTextWatcher(flexGrowInput, new NonNegativeDecimalInputValidator(), @@ -174,6 +179,26 @@ public class FlexItemEditFragment extends DialogFragment { new FlexEditTextWatcher(minHeightInput, new FixedDimensionInputValidator(), R.string.must_be_non_negative_integer)); + final TextInputLayout maxWidthInput = (TextInputLayout) view + .findViewById(R.id.input_layout_max_width); + EditText maxWidthEdit = (EditText) view.findViewById(R.id.edit_text_max_width); + maxWidthEdit.setText(String.valueOf(mFlexItem.maxWidth)); + maxWidthEdit.addTextChangedListener( + new FlexEditTextWatcher(maxWidthInput, new FixedDimensionInputValidator(), + R.string.must_be_non_negative_integer)); + + final TextInputLayout maxHeightInput = (TextInputLayout) view + .findViewById(R.id.input_layout_max_height); + EditText maxHeightEdit = (EditText) view.findViewById( + R.id.edit_text_max_height); + maxHeightEdit.setText(String.valueOf(mFlexItem.maxHeight)); + maxHeightEdit.addTextChangedListener( + new FlexEditTextWatcher(maxHeightInput, new FixedDimensionInputValidator(), + R.string.must_be_non_negative_integer)); + + setNextFocusesOnEnterDown(orderEdit, flexGrowEdit, flexShrinkEdit, flexBasisPercentEdit, + widthEdit, heightEdit, minWidthEdit, minHeightEdit, maxWidthEdit, maxHeightEdit); + Spinner alignSelfSpinner = (Spinner) view.findViewById( R.id.spinner_align_self); ArrayAdapter arrayAdapter = ArrayAdapter.createFromResource(getActivity(), @@ -219,7 +244,8 @@ public class FlexItemEditFragment extends DialogFragment { if (orderTextInput.isErrorEnabled() || flexGrowInput.isErrorEnabled() || flexBasisPercentInput.isErrorEnabled() || widthInput.isErrorEnabled() || heightInput.isErrorEnabled() || minWidthInput.isErrorEnabled() || - minHeightInput.isErrorEnabled()) { + minHeightInput.isErrorEnabled() || maxWidthInput.isErrorEnabled() || + maxHeightInput.isErrorEnabled()) { Toast.makeText(getActivity(), R.string.invalid_values_exist, Toast.LENGTH_SHORT) .show(); return; @@ -237,6 +263,42 @@ public class FlexItemEditFragment extends DialogFragment { mFlexItemChangedListener = flexItemChangedListener; } + private void setNextFocusesOnEnterDown(final TextView... textViews) { + for (int i = 0; i < textViews.length; i++) { + final int index = i; + textViews[index].setOnEditorActionListener(new TextView.OnEditorActionListener() { + @Override + public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { + if (actionId == EditorInfo.IME_ACTION_NEXT || + actionId == EditorInfo.IME_ACTION_DONE || + (actionId == EditorInfo.IME_NULL + && event.getAction() == KeyEvent.ACTION_DOWN + && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) { + if (index + 1 < textViews.length) { + textViews[index + 1].requestFocus(); + } else if (index == textViews.length - 1) { + InputMethodManager inputMethodManager + = (InputMethodManager) getActivity() + .getSystemService(Context.INPUT_METHOD_SERVICE); + inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0); + } + } + return true; + } + }); + + // Suppress the key focus change by KeyEvent.ACTION_UP of the enter key + textViews[index].setOnKeyListener(new View.OnKeyListener() { + @Override + public boolean onKey(View v, int keyCode, KeyEvent event) { + return keyCode == KeyEvent.KEYCODE_ENTER + && event.getAction() == KeyEvent.ACTION_UP; + } + }); + } + + } + private String alignSelfAsString(int alignSelf) { switch (alignSelf) { case FlexboxLayout.LayoutParams.ALIGN_SELF_AUTO: @@ -330,6 +392,12 @@ public class FlexItemEditFragment extends DialogFragment { case R.id.input_layout_min_height: mFlexItem.minHeight = intValue; break; + case R.id.input_layout_max_width: + mFlexItem.maxWidth = intValue; + break; + case R.id.input_layout_max_height: + mFlexItem.maxHeight = intValue; + break; } } } diff --git a/app/src/main/res/layout/fragment_flex_item_edit.xml b/app/src/main/res/layout/fragment_flex_item_edit.xml index f8e85771ad9aa90040f728c6e5a57a639d6f1cb0..c6d58105cc0b3a9f6761a6104e0a2cdb63612087 100644 --- a/app/src/main/res/layout/fragment_flex_item_edit.xml +++ b/app/src/main/res/layout/fragment_flex_item_edit.xml @@ -14,20 +14,27 @@ See the License for the specific language governing permissions and limitations under the License. --> + android:layout_height="match_parent" + android:layout_marginEnd="@dimen/activity_horizontal_margin" + android:layout_marginStart="@dimen/activity_horizontal_margin" + android:layout_marginTop="@dimen/activity_vertical_margin" + android:layout_marginBottom="@dimen/activity_vertical_margin" > - + android:paddingEnd="@dimen/margin_medium" + android:paddingStart="@dimen/margin_medium" + app:flexWrap="wrap"> + android:layout_width="100dp" + android:layout_height="wrap_content" + app:layout_flexGrow="1" + app:layout_flexBasisPercent="30%"> + android:layout_width="100dp" + android:layout_height="wrap_content" + app:layout_flexGrow="1" + app:layout_flexBasisPercent="30%"> + android:layout_width="100dp" + android:layout_height="wrap_content" + app:layout_flexGrow="1" + app:layout_flexBasisPercent="30%"> + android:layout_width="150dp" + android:layout_height="wrap_content" + app:layout_flexGrow="1" + app:layout_flexBasisPercent="90%"> + android:layout_width="300dp" + android:layout_height="wrap_content" + app:layout_flexGrow="1"> + android:layout_width="300dp" + android:layout_height="wrap_content" + app:layout_flexGrow="1"> + android:layout_width="150dp" + android:layout_height="wrap_content" + app:layout_flexGrow="1"> + android:layout_width="150dp" + android:layout_height="wrap_content" + app:layout_flexGrow="1"> + + + + + + + + + + - + diff --git a/app/src/main/res/values-w600dp/dimens.xml b/app/src/main/res/values-w600dp/dimens.xml new file mode 100644 index 0000000000000000000000000000000000000000..30607f7021cdac65f7c885646bdfd6f1163849eb --- /dev/null +++ b/app/src/main/res/values-w600dp/dimens.xml @@ -0,0 +1,20 @@ + + + + 64dp + 64dp + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 28b8259e5d0b31277d487e69a54d92a0b09e8e01..b4cb2a1763cb16c4226a5d76c68423a7a88598ea 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -102,6 +102,8 @@ limitations under the License. Height (-1: match_parent, -2: wrap_content) Min Width Min Height + Max Width + Max Height Must be a non-negative float value Must be a non-negative integer value