提交 b2051603 编写于 作者: E Evan Tatarka 提交者: Takeshi Hagikura

Updated sample app for min-width and min-height #1

上级 c98bbcc4
......@@ -64,6 +64,10 @@ public class FlexItem implements Parcelable {
public float flexBasisPercent;
public int minWidth;
public int minHeight;
public FlexItem() {
}
......@@ -90,6 +94,8 @@ public class FlexItem implements Parcelable {
dest.writeFloat(this.flexShrink);
dest.writeInt(this.alignSelf);
dest.writeFloat(this.flexBasisPercent);
dest.writeInt(this.minWidth);
dest.writeInt(this.minHeight);
}
protected FlexItem(Parcel in) {
......@@ -109,6 +115,8 @@ public class FlexItem implements Parcelable {
this.flexShrink = in.readFloat();
this.alignSelf = in.readInt();
this.flexBasisPercent = in.readFloat();
this.minWidth = in.readInt();
this.minHeight = in.readInt();
}
public FlexboxLayout.LayoutParams toLayoutParams(Context context) {
......@@ -124,6 +132,8 @@ public class FlexItem implements Parcelable {
MarginLayoutParamsCompat.setMarginStart(lp, startMargin);
MarginLayoutParamsCompat.setMarginEnd(lp, endMargin);
lp.bottomMargin = bottomMargin;
lp.minWidth = minWidth;
lp.minHeight = minHeight;
return lp;
}
......@@ -146,6 +156,8 @@ public class FlexItem implements Parcelable {
flexItem.paddingStart = ViewCompat.getPaddingStart(view);
flexItem.paddingEnd = ViewCompat.getPaddingEnd(view);
flexItem.paddingBottom = view.getPaddingBottom();
flexItem.minWidth = lp.minWidth;
flexItem.minHeight = lp.minHeight;
return flexItem;
}
......
......@@ -16,6 +16,7 @@
package com.google.android.apps.flexbox;
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;
......@@ -156,6 +157,23 @@ public class FlexItemEditFragment extends DialogFragment {
new FlexEditTextWatcher(heightInput, new DimensionInputValidator(),
R.string.must_be_minus_one_or_minus_two_or_non_negative_integer));
final TextInputLayout minWidthInput = (TextInputLayout) view
.findViewById(R.id.input_layout_min_width);
EditText minWidthEdit = (EditText) view.findViewById(R.id.edit_text_min_width);
minWidthEdit.setText(String.valueOf(mFlexItem.minWidth));
minWidthEdit.addTextChangedListener(
new FlexEditTextWatcher(minWidthInput, new FixedDimensionInputValidator(),
R.string.must_be_non_negative_integer));
final TextInputLayout minHeightInput = (TextInputLayout) view
.findViewById(R.id.input_layout_min_height);
EditText minHeightEdit = (EditText) view.findViewById(
R.id.edit_text_min_height);
minHeightEdit.setText(String.valueOf(mFlexItem.minHeight));
minHeightEdit.addTextChangedListener(
new FlexEditTextWatcher(minHeightInput, new FixedDimensionInputValidator(),
R.string.must_be_non_negative_integer));
Spinner alignSelfSpinner = (Spinner) view.findViewById(
R.id.spinner_align_self);
ArrayAdapter<CharSequence> arrayAdapter = ArrayAdapter.createFromResource(getActivity(),
......@@ -305,6 +323,12 @@ public class FlexItemEditFragment extends DialogFragment {
= FlexboxLayout.LayoutParams.FLEX_BASIS_PERCENT_DEFAULT;
}
break;
case R.id.input_layout_min_width:
mFlexItem.minWidth = intValue;
break;
case R.id.input_layout_min_height:
mFlexItem.minHeight = intValue;
break;
}
}
}
......
......@@ -19,7 +19,7 @@ package com.google.android.apps.flexbox.validators;
import android.text.TextUtils;
/**
* Validator for dimension values.
* Validator for dimension values including match_parent and wrap_content.
*/
public class DimensionInputValidator implements InputValidator {
......
/*
* 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.
*/
package com.google.android.apps.flexbox.validators;
import android.text.TextUtils;
/**
* Validator for dimension values.
*/
public class FixedDimensionInputValidator implements InputValidator {
@Override
public boolean isValidInput(CharSequence charSequence) {
return !TextUtils.isEmpty(charSequence) && TextUtils.isDigitsOnly(charSequence);
}
}
......@@ -114,6 +114,36 @@ limitations under the License.
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_min_width"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/edit_text_min_width"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="1"
android:singleLine="true"
android:inputType="number"
android:hint="@string/hint_min_width" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_min_height"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/edit_text_min_height"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="1"
android:singleLine="true"
android:inputType="number"
android:hint="@string/hint_min_height" />
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
......
......@@ -100,8 +100,11 @@ limitations under the License.
<string name="hint_align_self">Align Self</string>
<string name="hint_width">Width (-1: match_parent, -2: wrap_content)</string>
<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="must_be_non_negative_float">Must be a non-negative float value</string>
<string name="must_be_non_negative_integer">Must a non-negative integer value</string>
<string name="must_be_minus_one_or_minus_two_or_non_negative_integer">Must be -1 or -2 or a non-negative integer value</string>
<string name="must_be_integer">Must be an integer value</string>
<string name="must_be_minus_one_or_non_negative_integer">Must be -1 or a non-negative integer value</string>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册