Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
门心叼龙
flexbox-layout
提交
0a0259dd
F
flexbox-layout
项目概览
门心叼龙
/
flexbox-layout
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
flexbox-layout
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
0a0259dd
编写于
6月 02, 2016
作者:
T
Takeshi Hagikura
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #59 from google/replace_linearlayout_with_flexboxlayout
Replace the LinearLayout with FlexboxLayout
上级
3c9573c8
ca4989a6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
164 addition
and
25 deletion
+164
-25
app/src/main/java/com/google/android/apps/flexbox/FlexItemEditFragment.java
...com/google/android/apps/flexbox/FlexItemEditFragment.java
+71
-3
app/src/main/res/layout/fragment_flex_item_edit.xml
app/src/main/res/layout/fragment_flex_item_edit.xml
+71
-22
app/src/main/res/values-w600dp/dimens.xml
app/src/main/res/values-w600dp/dimens.xml
+20
-0
app/src/main/res/values/strings.xml
app/src/main/res/values/strings.xml
+2
-0
未找到文件。
app/src/main/java/com/google/android/apps/flexbox/FlexItemEditFragment.java
浏览文件 @
0a0259dd
...
...
@@ -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
;
}
}
}
...
...
app/src/main/res/layout/fragment_flex_item_edit.xml
浏览文件 @
0a0259dd
...
...
@@ -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"
>
<
Linear
Layout
<
com.google.android.flexbox.Flexbox
Layout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:
orientation=
"vertical
"
android:padding
End=
"@dimen/activity_horizontal_margin
"
a
ndroid:paddingStart=
"@dimen/activity_horizontal_margin
"
>
android:
paddingEnd=
"@dimen/margin_medium
"
android:padding
Start=
"@dimen/margin_medium
"
a
pp: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>
</
Linear
Layout>
</
com.google.android.flexbox.Flexbox
Layout>
</ScrollView>
app/src/main/res/values-w600dp/dimens.xml
0 → 100644
浏览文件 @
0a0259dd
<?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>
app/src/main/res/values/strings.xml
浏览文件 @
0a0259dd
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录