新增 fab控件及其例子
This commit is contained in:
115
app/src/main/assets/sample/复杂界面/待办事项.js
Normal file
115
app/src/main/assets/sample/复杂界面/待办事项.js
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
"ui";
|
||||||
|
|
||||||
|
importClass(android.graphics.Paint);
|
||||||
|
|
||||||
|
ui.layout(
|
||||||
|
<frame>
|
||||||
|
<vertical>
|
||||||
|
<appbar>
|
||||||
|
<toolbar id="toolbar" title="Todo" />
|
||||||
|
</appbar>
|
||||||
|
<list id="todoList">
|
||||||
|
<card w="*" h="70" margin="10 5" cardCornerRadius="2dp"
|
||||||
|
cardElevation="1dp" foreground="?selectableItemBackground">
|
||||||
|
<horizontal gravity="center_vertical">
|
||||||
|
<View bg="{{this.color}}" h="*" w="10" />
|
||||||
|
<vertical padding="10 8" h="auto" w="0" layout_weight="1">
|
||||||
|
<text id="title" text="{{this.title}}" textColor="#222222" textSize="16sp" maxLines="1" />
|
||||||
|
<text text="{{this.summary}}" textColor="#999999" textSize="14sp" maxLines="1" />
|
||||||
|
</vertical>
|
||||||
|
<checkbox id="done" marginLeft="4" marginRight="6" checked="{{this.done}}" />
|
||||||
|
</horizontal>
|
||||||
|
|
||||||
|
</card>
|
||||||
|
</list>
|
||||||
|
</vertical>
|
||||||
|
<fab id="add" w="auto" h="auto" src="@drawable/ic_add_black_48dp"
|
||||||
|
margin="16" layout_gravity="bottom|right" tint="#ffffff" />
|
||||||
|
</frame>
|
||||||
|
);
|
||||||
|
|
||||||
|
var materialColors = ["#e91e63", "#ab47bc", "#5c6bc0", "#7e57c2", "##2196f3", "#00bcd4",
|
||||||
|
"#26a69a", "#4caf50", "#8bc34a", "#ffeb3b", "#ffa726", "#78909c", "#8d6e63"];
|
||||||
|
|
||||||
|
var storage = storages.create("todoList");
|
||||||
|
//从storage获取todo列表
|
||||||
|
var todoList = storage.get("items", [
|
||||||
|
{
|
||||||
|
title: "写操作系统作业",
|
||||||
|
summary: "明天第1~2节",
|
||||||
|
color: "#f44336",
|
||||||
|
done: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "给ui模式增加若干Bug",
|
||||||
|
summary: "无限期",
|
||||||
|
color: "#ff5722",
|
||||||
|
done: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "发布Auto.js 5.0.0正式版",
|
||||||
|
summary: "2019年1月",
|
||||||
|
color: "#4caf50",
|
||||||
|
done: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "完成毕业设计和论文",
|
||||||
|
summary: "2019年4月",
|
||||||
|
color: "#2196f3",
|
||||||
|
done: false
|
||||||
|
}
|
||||||
|
]);;
|
||||||
|
|
||||||
|
ui.todoList.setDataSource(todoList);
|
||||||
|
|
||||||
|
ui.todoList.on("item_bind", function (itemView, itemHolder) {
|
||||||
|
//绑定勾选框事件
|
||||||
|
itemView.done.on("check", function (checked) {
|
||||||
|
let item = itemHolder.item;
|
||||||
|
item.done = checked;
|
||||||
|
let paint = itemView.title.paint;
|
||||||
|
//设置或取消中划线效果
|
||||||
|
if (checked) {
|
||||||
|
paint.flags |= Paint.STRIKE_THRU_TEXT_FLAG;
|
||||||
|
} else {
|
||||||
|
paint.flags &= ~Paint.STRIKE_THRU_TEXT_FLAG;
|
||||||
|
}
|
||||||
|
itemView.title.invalidate();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.todoList.on("item_click", function (item, i, itemView, listView) {
|
||||||
|
itemView.done.checked = !itemView.done.checked;
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.todoList.on("item_long_click", function (e, item, i, itemView, listView) {
|
||||||
|
confirm("确定要删除" + item.title + "吗?")
|
||||||
|
.then(ok => {
|
||||||
|
if (ok) {
|
||||||
|
todoList.splice(i, 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
e.consumed = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
//当离开本界面时保存todoList
|
||||||
|
ui.emitter.on("pause", () => {
|
||||||
|
storage.put("items", todoList);
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.add.on("click", () => {
|
||||||
|
dialogs.rawInput("请输入标题")
|
||||||
|
.then(title => {
|
||||||
|
if (!title) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dialogs.rawInput("请输入期限", "明天")
|
||||||
|
.then(summary => {
|
||||||
|
todoList.push({
|
||||||
|
title: title,
|
||||||
|
summary: summary,
|
||||||
|
color: materialColors[random(0, materialColors.length - 1)]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
"ui";
|
|
||||||
|
|
||||||
ui.layout(
|
|
||||||
<frame>
|
|
||||||
<vertical>
|
|
||||||
<appbar>
|
|
||||||
<toolbar id="toolbar" title="卡片布局" />
|
|
||||||
</appbar>
|
|
||||||
<list id="todos">
|
|
||||||
<card w="*" h="70" margin="10 5" cardCornerRadius="2dp"
|
|
||||||
cardElevation="1dp" gravity="center_vertical">
|
|
||||||
<vertical padding="18 8" h="auto">
|
|
||||||
<text text="{{this.title}}" textColor="#222222" textSize="16sp" />
|
|
||||||
<text text="{{this.summary}}" textColor="#999999" textSize="14sp" />
|
|
||||||
</vertical>
|
|
||||||
<View bg="{{this.color}}" h="*" w="10" />
|
|
||||||
</card>
|
|
||||||
</list>
|
|
||||||
</vertical>
|
|
||||||
</frame>
|
|
||||||
);
|
|
||||||
|
|
||||||
var todos = [
|
|
||||||
{
|
|
||||||
title: "",
|
|
||||||
summary: "",
|
|
||||||
color: ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "",
|
|
||||||
summary: "",
|
|
||||||
color: ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "",
|
|
||||||
summary: "",
|
|
||||||
color: ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "",
|
|
||||||
summary: "",
|
|
||||||
color: ""
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
ui.todos.setDataSource(todos);
|
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.stardust.autojs.core.ui.attribute;
|
||||||
|
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.support.design.widget.FloatingActionButton;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
|
||||||
|
import com.stardust.autojs.core.ui.inflater.ResourceParser;
|
||||||
|
|
||||||
|
public class FabViewAttributes extends ImageViewAttributes {
|
||||||
|
|
||||||
|
public FabViewAttributes(ResourceParser resourceParser, View view) {
|
||||||
|
super(resourceParser, view);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onRegisterAttrs() {
|
||||||
|
super.onRegisterAttrs();
|
||||||
|
registerPixelAttr("elevation", getView()::setCompatElevation);
|
||||||
|
registerIntPixelAttr("fabCustomSize", getView()::setCustomSize);
|
||||||
|
registerIntPixelAttr("fabSize", getView()::setSize);
|
||||||
|
registerAttr("rippleColor", Color::parseColor, getView()::setRippleColor);
|
||||||
|
registerBooleanAttr("useCompatPadding", getView()::setUseCompatPadding);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FloatingActionButton getView() {
|
||||||
|
return (FloatingActionButton) super.getView();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.stardust.autojs.core.ui.attribute;
|
package com.stardust.autojs.core.ui.attribute;
|
||||||
|
|
||||||
import android.support.design.widget.AppBarLayout;
|
import android.support.design.widget.AppBarLayout;
|
||||||
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.v7.widget.CardView;
|
import android.support.v7.widget.CardView;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
@@ -24,6 +25,7 @@ public class ViewAttributesFactory {
|
|||||||
sViewAttributesCreators.put(AppBarLayout.class, AppbarAttributes::new);
|
sViewAttributesCreators.put(AppBarLayout.class, AppbarAttributes::new);
|
||||||
sViewAttributesCreators.put(TextView.class, TextViewAttributes::new);
|
sViewAttributesCreators.put(TextView.class, TextViewAttributes::new);
|
||||||
sViewAttributesCreators.put(CardView.class, CardAttributes::new);
|
sViewAttributesCreators.put(CardView.class, CardAttributes::new);
|
||||||
|
sViewAttributesCreators.put(FloatingActionButton.class, FabViewAttributes::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void put(Class<? extends View> clazz, ViewAttributesCreator creator) {
|
public static void put(Class<? extends View> clazz, ViewAttributesCreator creator) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.stardust.autojs.core.ui.xml;
|
package com.stardust.autojs.core.ui.xml;
|
||||||
|
|
||||||
import android.support.design.widget.AppBarLayout;
|
import android.support.design.widget.AppBarLayout;
|
||||||
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.design.widget.TabLayout;
|
import android.support.design.widget.TabLayout;
|
||||||
import android.support.v4.widget.DrawerLayout;
|
import android.support.v4.widget.DrawerLayout;
|
||||||
import android.support.v7.widget.CardView;
|
import android.support.v7.widget.CardView;
|
||||||
@@ -84,6 +85,7 @@ public class XmlConverter {
|
|||||||
.map("tabs", JsTabLayout.class.getName())
|
.map("tabs", JsTabLayout.class.getName())
|
||||||
.map("viewpager", JsViewPager.class.getName())
|
.map("viewpager", JsViewPager.class.getName())
|
||||||
.map("card", CardView.class.getName())
|
.map("card", CardView.class.getName())
|
||||||
|
.map("fab", FloatingActionButton.class.getName())
|
||||||
);
|
);
|
||||||
|
|
||||||
private static final AttributeHandler ATTRIBUTE_HANDLER = new AttributeHandler.AttrNameRouter()
|
private static final AttributeHandler ATTRIBUTE_HANDLER = new AttributeHandler.AttrNameRouter()
|
||||||
|
|||||||
Reference in New Issue
Block a user