提交 0a0259dd 编写于 作者: T Takeshi Hagikura

Merge pull request #59 from google/replace_linearlayout_with_flexboxlayout

Replace the LinearLayout with FlexboxLayout
......@@ -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<CharSequence> 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;
}
}
}
......
......@@ -14,20 +14,27 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
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" >
<LinearLayout
<com.google.android.flexbox.FlexboxLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingEnd="@dimen/activity_horizontal_margin"
android:paddingStart="@dimen/activity_horizontal_margin">
android:paddingEnd="@dimen/margin_medium"
android:paddingStart="@dimen/margin_medium"
app:flexWrap="wrap">
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_order"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_width="100dp"
android:layout_height="wrap_content"
app:layout_flexGrow="1"
app:layout_flexBasisPercent="30%">
<EditText
android:id="@+id/edit_text_order"
......@@ -41,8 +48,10 @@ limitations under the License.
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_flex_grow"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_width="100dp"
android:layout_height="wrap_content"
app:layout_flexGrow="1"
app:layout_flexBasisPercent="30%">
<EditText
android:id="@+id/edit_text_flex_grow"
......@@ -56,8 +65,10 @@ limitations under the License.
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_flex_shrink"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_width="100dp"
android:layout_height="wrap_content"
app:layout_flexGrow="1"
app:layout_flexBasisPercent="30%">
<EditText
android:id="@+id/edit_text_flex_shrink"
......@@ -71,8 +82,10 @@ limitations under the License.
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_flex_basis_percent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_width="150dp"
android:layout_height="wrap_content"
app:layout_flexGrow="1"
app:layout_flexBasisPercent="90%">
<EditText
android:id="@+id/edit_text_flex_basis_percent"
......@@ -86,8 +99,9 @@ limitations under the License.
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_width"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_width="300dp"
android:layout_height="wrap_content"
app:layout_flexGrow="1">
<EditText
android:id="@+id/edit_text_width"
......@@ -101,8 +115,9 @@ limitations under the License.
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_height"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_width="300dp"
android:layout_height="wrap_content"
app:layout_flexGrow="1">
<EditText
android:id="@+id/edit_text_height"
......@@ -116,8 +131,9 @@ limitations under the License.
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_min_width"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_width="150dp"
android:layout_height="wrap_content"
app:layout_flexGrow="1">
<EditText
android:id="@+id/edit_text_min_width"
......@@ -131,8 +147,9 @@ limitations under the License.
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_min_height"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_width="150dp"
android:layout_height="wrap_content"
app:layout_flexGrow="1">
<EditText
android:id="@+id/edit_text_min_height"
......@@ -144,6 +161,38 @@ limitations under the License.
android:hint="@string/hint_min_height" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_max_width"
android:layout_width="150dp"
android:layout_height="wrap_content"
app:layout_flexGrow="1">
<EditText
android:id="@+id/edit_text_max_width"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="1"
android:singleLine="true"
android:inputType="number"
android:hint="@string/hint_max_width" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_max_height"
android:layout_width="150dp"
android:layout_height="wrap_content"
app:layout_flexGrow="1">
<EditText
android:id="@+id/edit_text_max_height"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="1"
android:singleLine="true"
android:inputType="number"
android:hint="@string/hint_max_height" />
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
......@@ -196,5 +245,5 @@ limitations under the License.
android:layout_height="wrap_content"
android:text="@string/ok" />
</LinearLayout>
</LinearLayout>
</com.google.android.flexbox.FlexboxLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2016 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">64dp</dimen>
<dimen name="activity_vertical_margin">64dp</dimen>
</resources>
......@@ -102,6 +102,8 @@ limitations under the License.
<string name="hint_height">Height (-1: match_parent, -2: wrap_content)</string>
<string name="hint_min_width">Min Width</string>
<string name="hint_min_height">Min Height</string>
<string name="hint_max_width">Max Width</string>
<string name="hint_max_height">Max Height</string>
<string name="must_be_non_negative_float">Must be a non-negative float value</string>
<string name="must_be_non_negative_integer">Must be a non-negative integer value</string>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册