├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── XJsonViewLib
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── arthas
│ │ └── xjsonview
│ │ ├── ComponentManager.java
│ │ ├── SimpleXViewComponent.java
│ │ ├── Utils.java
│ │ ├── XViewComponent.java
│ │ ├── XViewEngine.java
│ │ ├── XViewImageAdapter.java
│ │ ├── XViewMain.java
│ │ ├── XViewStore.java
│ │ ├── XiewConfig.java
│ │ ├── bean
│ │ ├── PropertyBean.java
│ │ ├── XView.java
│ │ ├── XViewBase.java
│ │ ├── XViewBody.java
│ │ └── XViewHead.java
│ │ └── process
│ │ ├── FrameLayoutProcess.java
│ │ ├── HorizonLayoutProcess.java
│ │ ├── ImageViewComponent.java
│ │ ├── RelativeLayoutProcess.java
│ │ ├── ScrollViewProcess.java
│ │ ├── SimpleViewProcess.java
│ │ ├── TextViewProcess.java
│ │ ├── VerticalLayoutProcess.java
│ │ ├── base
│ │ ├── LayoutProcess.java
│ │ ├── ViewGroupProcess.java
│ │ └── ViewProcess.java
│ │ ├── diy
│ │ └── ScrollComponent.java
│ │ └── list
│ │ ├── AdapterHelper.java
│ │ ├── RecyclerAdapter.java
│ │ └── RecyclerViewComponent.java
│ └── res
│ └── values
│ └── strings.xml
├── build.gradle
├── example_assets
├── how_it_works.png
├── json2view.png
├── test00.png
└── test01.png
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── javaCodeGenerate
├── .gitignore
├── build.gradle
├── complaintDetail.json
├── libs
│ ├── jackson-annotations-2.8.0.jar
│ ├── jackson-core-2.8.6.jar
│ ├── jackson-databind-2.8.6.jar
│ ├── jackson-datatype-jsr310-2.6.7.jar
│ └── json-lib-2.4-jdk15.jar
├── src
│ └── main
│ │ └── java
│ │ └── com
│ │ └── yi
│ │ ├── UtilCopyMethod.java
│ │ ├── bean
│ │ ├── ComponentBean.java
│ │ ├── HeadBean.java
│ │ ├── PropertyBean.java
│ │ ├── Yiew.java
│ │ ├── YiewBean.java
│ │ └── YiewResp.java
│ │ └── generate
│ │ ├── ServerCodeGenerate.java
│ │ ├── ServerCodeGenerateTest.java
│ │ ├── UtilCopyMethod.java
│ │ ├── UtilCopyMethod2.java
│ │ └── YiewSerializeGererate.java
└── textview.json
├── sample
├── .gitignore
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── assets
│ ├── complaintDetail.json
│ ├── feature.json
│ ├── headComponent.json
│ ├── images.json
│ ├── main.json
│ ├── sales.json
│ ├── simple.json
│ └── virtual.json
│ ├── java
│ ├── com
│ │ └── avocarrot
│ │ │ └── json2view
│ │ │ └── sample
│ │ │ ├── App.java
│ │ │ ├── ImageAdapter.java
│ │ │ └── MainActivity.java
│ ├── flex
│ │ └── FlexActivity.java
│ ├── weexact
│ │ └── WeexActivity1.java
│ └── yiewdemo
│ │ ├── FeatureActivity.java
│ │ ├── HeadComponentActivity.java
│ │ ├── JsonFromLocalActivity.java
│ │ ├── JsonImageActivity.java
│ │ ├── SalesActivity.java
│ │ ├── Util.java
│ │ ├── VirtualVNodeActivity.java
│ │ └── YiewCodeActivity.java
│ └── res
│ ├── drawable-hdpi
│ └── icon.png
│ ├── drawable-mdpi
│ └── icon.png
│ ├── drawable-xhdpi
│ └── icon.png
│ ├── drawable-xxhdpi
│ └── icon.png
│ ├── drawable
│ └── sample.png
│ ├── layout
│ ├── aa.xml
│ ├── flexlayout.xml
│ └── imageview.xml
│ └── values
│ ├── strings.xml
│ └── styles.xml
├── settings.gradle
└── utils
├── build.gradle
└── src
└── main
└── groovy
└── ConvertXML2Json.groovy
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | # Log Files
26 | *.log
27 |
28 | */**/*.iml
29 | *.iml
30 |
31 | .idea/*
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 |
3 | jdk:
4 | - oraclejdk8
5 |
6 | android:
7 | components:
8 | # Uncomment the lines below if you want to
9 | # use the latest revision of Android SDK Tools
10 | - platform-tools
11 | - tools
12 |
13 | # The BuildTools version used by your project
14 | - build-tools-24.0.2
15 |
16 | # The SDK version used to compile your project
17 | - android-23
18 |
19 | # Additional components
20 | - extra-google-google_play_services
21 | - extra-google-m2repository
22 | - extra-android-m2repository
23 | - addon-google_apis-google-24
24 |
25 | # Specify at least one system image,
26 | # if you need to run emulator(s) during your tests
27 | - sys-img-armeabi-v7a-android-21
28 | # - sys-img-x86-android-21
29 |
30 | licenses:
31 | - android-sdk-license-.+
32 | - android-sdk-license-c81a61d9
33 |
34 | notifications:
35 | email: false
36 |
37 | # Emulator Management: Create, Start and Wait
38 | before_script:
39 | - echo "y" | android update sdk --no-ui
40 | - echo no | android create avd --force -n test -t android-21 --abi armeabi-v7a
41 | - emulator -avd test -no-skin -no-audio -no-window &
42 | - android-wait-for-emulator
43 | - adb shell input keyevent 82 &
44 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Avocarrot
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | **根据json数据创建view**
5 |
6 | >##### 简介
7 |
8 | json2view is a simple library that can convert a compatible JSON file to an Android view
9 | so you can load dynamically the view in your Android app without the need to update the APK.
10 | 根据https://github.com/Avocarrot/json2view 自己手动修改成自己所需要的数据结构
11 |
12 | >##### 使用场景
13 |
14 | 1. 使用json创建本地视图,json文件放置在assets,可以使用子文件夹,分门别类管理。
15 | 2. 根据服务器返回的json view数据动态创建视图,若需要界面的更改,一定程度上更改服务器代码即可更改界面。
16 | 3. 搭建静态服务器,请求json文件渲染本地视图,可以达到更改json,一秒钟更新界面,达到敏捷开发的目的。
17 | 4. 搭配使用热更新框架,如andfix,json2view来改变视图,andfix更改逻辑,可以动态改变整个activity的大多数需求。
18 | 5. 后期若加上flexboxlayout的布局,Android和ios 各有一个flexboxlayout的布局库,ios再实现一套json2view的引擎, 可以达到写一次json文件,就可以产生ios和Android两个原生界面,且布局相差不大,减少开发工作量。
19 |
20 |
21 | >##### 优缺点
22 |
23 | 优点:
24 | 1. 搭建静态服务器,请求json文件渲染本地视图,可以达到更改json,一秒钟更新界面,达到敏捷开发的目的。
25 | 2. json数据若服务器返回,则可以动态改变视图界面。
26 |
27 |
28 | 缺点:
29 | 1. 不能更改逻辑,只有视图功能。
30 | 2. json文件没有提示功能。
31 | 3. 暂不支持list。
32 | 4. 目前支持的功能比较简单,用作简单的展示界面或简单逻辑的界面,不能应用于逻辑复杂的界面。
33 |
34 | #####[一个简单的零配置命令行HTTP服务器 - http-server (nodeJs)](http://www.cnblogs.com/lucker/p/4108838.html)
35 | >##### 使用
36 |
37 | > 1.创建json文件
38 |
39 | {
40 | "head": {
41 | "process": "AndroidLayout"
42 | },
43 | "template": {
44 | "view": "verticalLayout",
45 | "width": "match",
46 | "height": "match",
47 | "background": "#f6f6f6",
48 | "child": [
49 | {
50 | "view": "TextView",
51 | "text": "页面的简单使用",
52 | "width": "120dp",
53 | "height": "30dp",
54 | "textColor": "#444444",
55 | "padding": "16dp",
56 | "textSize": "16"
57 | }
58 | ]
59 | }
60 | }
61 | > 2.把json bean 转为View
62 |
63 | XView xview = gson.fromJson(jsonString, XView.class);
64 |
65 | View contentView = XViewMain.startProcess(context, xview );
66 |
67 | setContentView(contentView);
68 |
69 |
70 | >##### 组件
71 |
72 |
73 | View 组件
74 |
75 | |属性 | Type | 说明 | 可选值|
76 | |:----- |:----------|:-----------|:------ |
77 | |id |int | | id >=1 |
78 | |tag |String | | |
79 | |padding |String | 默认单位dp,10dp,10px | |
80 | |background |String | 网络图片 | |
81 | |onClick |String | 方法名 | |
82 | |visibility |String | | gone visible invisible |
83 |
84 |
85 | ViewGroup 属性
86 |
87 | |属性 | Type | 说明 | 可选值|
88 | |:----- |:----------|:-----------|:------ |
89 | |padding |String | 默认单位dp , 10dp,10px | |
90 |
91 |
92 | TextView 属性
93 |
94 | |属性 | Type | 说明 | 可选值|
95 | |:----- |:----------|:-----------|:------ |
96 | |text |String | | |
97 | |textColor |String | #123443 | |
98 | |textSize |String | 默认单位sp | |
99 | |maxLine |int | | |
100 | |hint |String | | |
101 | |hintColor |String | | |
102 | |lineSpace |String | android:lineSpacingExtra="4dp" | |
103 | |gravity |String | 大小写不敏感 | CENTER_VERTICAL等 |
104 |
105 |
106 | ImageView 属性
107 |
108 | |属性 | Type | 说明 | 可选值|
109 | |:----- |:----------|:-----------|:------ |
110 | |src |String | 网络图片 | |
111 | |scaleType |String | 默认FIT_XY | MATRIX,FIT_XY,FIT_START,FIT_CENTER等 |
112 |
113 |
114 | FrameLayout
115 |
116 | |属性 | Type | 说明 | 可选值|
117 | |:----- |:----------|:-----------|:------ |
118 | |gravity |String | 大小写不敏感 | CENTER_VERTICAL等 |
119 |
120 |
121 | LinearLayout 分为 VerticalLayout ,HorizonLayout
122 |
123 | |属性 | Type | 说明 | 可选值|
124 | |:----- |:----------|:-----------|:------ |
125 | |gravity |String | 大小写不敏感 | CENTER_VERTICAL等 |
126 | |weight |int | | |
127 |
128 |
129 |
130 | RelativeLayout
131 |
132 | |属性 | Type | 说明 | 可选值|
133 | |:----- |:----------|:-----------|:------ |
134 | |layout_alignParentLeft |bool | | |
135 | |layout_alignParentTop |bool | | |
136 | |layout_alignParentRight |bool | | |
137 | |layout_alignParentBottom |bool | | |
138 | |layout_centerInParent |bool | | |
139 | |layout_centerHorizontal |bool | | |
140 | |layout_centerVertical |bool | | |
141 | |below |String | | |
142 | |toLeftOf |String | | |
143 | |toRightOf |String | | |
144 | |above |String | | |
145 | |alignLeft |String | | |
146 | |alignRight |String | | |
147 | |alignTop |String | | |
148 | |alignBottom |String | | |
149 | |alignBaseline |String | | |
150 |
151 | ScrollView
152 |
153 | |属性 | Type | 说明 | 可选值|
154 | |:----- |:----------|:-----------|:------ |
155 | |无属性 |int | 默认scrollbar=none | |
156 |
157 |
158 |
159 |
160 | 扩展字段
161 |
162 | |属性 | Type | 说明 | 可选值|
163 | |:----- |:----------|:-----------|:------ |
164 | |name |String | 组件的名字,把RelativeLayout的相关越约束用name代替id | |
165 | |child |数组 | 子控件列表 | |
166 | |data |数组 | 组件的数据 | |
167 |
168 | gravity 取值TOP,BOTTOM,LEFT,RIGHT,CENTER_VERTICAL,FILL_VERTICAL,CENTER_HORIZONTAL,FILL_HORIZONTAL,CENTER
169 |
170 | >##### 性能与测试
171 |
172 | 运用比较稳定,运用反射的地方不多,性能的影响微乎其微。
173 |
174 | >##### 后续
175 |
176 | 1. 实现flexboxlayout
177 | 2. 与热更新同时使用
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 | >example 例子
187 |
188 | ```markdown
189 | {
190 | "view": "scrollView",
191 | "width": "match",
192 | "height": "match",
193 | "background": "#f6f6f6",
194 | "child": [
195 | {
196 | "view": "RelativeLayout",
197 | "width": "match",
198 | "height": "wrap",
199 | "background": "#ffffff",
200 | "property": {
201 | },
202 | "child": [
203 | {
204 | "id": 1001,
205 | "view": "TextView",
206 | "width": "wrap",
207 | "text": "bb",
208 | "textColor": "#333333",
209 | "height": "wrap",
210 | "margin": "20",
211 | "click": "myClick",
212 | "background": "#cccccc",
213 | "padding": "20"
214 |
215 | },
216 | {
217 | "id": 1002,
218 | "view": "TextView",
219 | "width": "100",
220 | "text": "cc",
221 | "textColor": "#666666",
222 | "height": "wrap",
223 |
224 | "click": "myClick2",
225 | "background": "#eeeeee",
226 |
227 | "layout_alignParentRight":true
228 | },
229 | {
230 | "id": 1003,
231 | "view": "TextView",
232 | "width": "wrap",
233 | "text": "below",
234 | "textColor": "#666666",
235 | "height": "wrap",
236 |
237 |
238 | "background": "#aaaaaa",
239 |
240 | "layout_below": 1002,
241 | "layout_alignLeft": 1002
242 |
243 | }
244 |
245 | ]
246 | },
247 | {
248 | "view": "View",
249 | "width": "match",
250 | "unit": "px",
251 | "height": "1",
252 | "background": "#e1e1e1"
253 | },
254 | {
255 | "view": "horizonLayout",
256 | "width": "match",
257 | "height": "wrap",
258 | "child": [
259 |
260 | ]
261 | },
262 | {
263 | "view": "TextView",
264 | "width": "wrap",
265 | "text": "asdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasda",
266 | "textColor": "#333333",
267 | "height": "wrap",
268 | "margin": "20",
269 | "background": "#cccccc",
270 | "padding": "20"
271 | }
272 | ]
273 | }
274 |
275 | ```
276 |
277 |
278 |
279 |
280 |
281 |
282 |
--------------------------------------------------------------------------------
/XJsonViewLib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/XJsonViewLib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.0"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 |
13 |
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile fileTree(dir: 'libs', include: ['*.jar'])
26 |
27 | compile 'com.apkfuns.logutils:library:1.5.1.1'
28 | compile 'com.android.support:appcompat-v7:25.0.0'
29 | compile 'com.android.support:support-v4:25.0.0'
30 | compile 'com.android.support:recyclerview-v7:25.0.0'
31 | compile 'com.google.code.gson:gson:2.7'
32 | }
33 |
--------------------------------------------------------------------------------
/XJsonViewLib/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/zhangyn/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the setComponentTemplate path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/ComponentManager.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview;
2 |
3 | import com.arthas.xjsonview.bean.XView;
4 |
5 | /**
6 | * Created by zhangyn on 17/4/14.
7 | */
8 |
9 | public class ComponentManager {
10 | public static XViewComponent findComponent(String view, XViewStore yiewStore) {
11 | if (yiewStore!= null)
12 | {
13 | XViewComponent component = yiewStore.findComponent(view);
14 | if (component != null)
15 | {
16 | return component;
17 |
18 | }
19 | }
20 |
21 | XViewComponent component1 = XiewConfig.findComponent(view);
22 | if (component1 != null)
23 | {
24 | return component1;
25 |
26 | }
27 | return null;
28 |
29 | }
30 |
31 |
32 |
33 | public static void addSimpleXViewComponent(XView yiewResp, SimpleXViewComponent yiewComponent, XViewStore yiewStore) {
34 | if (yiewResp.scope == null) {
35 | yiewStore.addComponent(yiewComponent.getTemplate().name, yiewComponent);
36 | } else if ("global".equals(yiewResp.scope)) {
37 | XiewConfig.addComponent(yiewComponent.getTemplate().name, yiewComponent);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/SimpleXViewComponent.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 |
7 | import com.arthas.xjsonview.bean.XViewBody;
8 |
9 | public class SimpleXViewComponent implements XViewComponent {
10 |
11 |
12 | private XViewBody template;
13 | public SimpleXViewComponent() {
14 |
15 | }
16 | public SimpleXViewComponent(XViewBody template) {
17 | this.template=template;
18 | }
19 |
20 | public XViewBody getTemplate() {
21 | return template;
22 | }
23 |
24 | @Override
25 | public View createComponentView(Context context, ViewGroup parent, XViewBody yiew) {
26 | XViewBody template = createTemplate(context, parent, yiew);
27 | XViewBody clone = template.deepClone();
28 |
29 | // if (yiew == null)
30 | // {
31 | // yiew = clone;
32 | // }else
33 | // {
34 | // yiew.setComponentTemplate(clone);
35 | // }
36 | yiew.setComponentTemplate(clone);
37 |
38 | View content = XViewEngine.createView(context, parent, yiew);
39 | return content;
40 | }
41 |
42 | @Override
43 | public void render(XViewBody yiew) {
44 |
45 | recu(yiew);
46 | }
47 |
48 | private void recu(XViewBody yiew) {
49 |
50 | XViewComponent component = ComponentManager.findComponent(yiew.view,yiew.getYiewStore());
51 |
52 | component.render(yiew);
53 | if (yiew.child!= null && yiew.child.size()>0){
54 | for (XViewBody xViewBody : yiew.child) {
55 | recu(xViewBody);
56 | }
57 | }
58 |
59 | }
60 |
61 | public XViewBody createTemplate(Context context, ViewGroup parent, XViewBody yiew){
62 | return template;
63 | }
64 | }
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/Utils.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.graphics.Color;
6 | import android.util.Log;
7 | import android.util.TypedValue;
8 | import android.view.ViewGroup;
9 |
10 | import com.arthas.xjsonview.bean.XViewBody;
11 | import com.arthas.xjsonview.bean.XViewBase;
12 |
13 | import java.util.concurrent.atomic.AtomicInteger;
14 |
15 | /**
16 | * Created by Administrator on 2016/10/28.
17 | */
18 |
19 | public class Utils {
20 |
21 |
22 | public static int dip2px(float dipValue)
23 |
24 | {
25 | float v = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, Resources.getSystem().getDisplayMetrics());
26 | return (int) v;
27 | }
28 |
29 |
30 | public static ViewGroup.LayoutParams createLayoutParams(ViewGroup viewGroup, XViewBase yiew) {
31 | ViewGroup.LayoutParams params = null;
32 | if (viewGroup != null) {
33 | try {
34 | /* find parent viewGroup and create LayoutParams of that class */
35 | Class layoutClass = viewGroup.getClass();
36 | while (!classExists(layoutClass.getName() + "$LayoutParams")) {
37 | layoutClass = layoutClass.getSuperclass();
38 | }
39 | String layoutParamsClassname = layoutClass.getName() + "$LayoutParams";
40 | Class layoutParamsClass = Class.forName(layoutParamsClassname);
41 | /* create the actual layoutParams object */
42 | params = (ViewGroup.LayoutParams) layoutParamsClass.getConstructor(Integer.TYPE, Integer.TYPE).
43 | newInstance(new Object[]{Utils.getWidth(yiew), Utils.getHeight(yiew)});
44 | } catch (Exception e) {
45 | e.printStackTrace();
46 | }
47 | }
48 | if (params == null) {
49 | params = new ViewGroup.LayoutParams(Utils.getWidth(yiew), Utils.getHeight(yiew));
50 | }
51 |
52 |
53 | return params;
54 | }
55 |
56 | private static int getHeight(XViewBase yiew) {
57 | // Log.d("syb", "getHeight=" + yiew.height);
58 | int meature = meature(yiew.height);
59 | // Log.d("syb", "getHeight=" + meature);
60 | return meature;
61 | }
62 |
63 | private static int getWidth(XViewBase yiew) {
64 | // Log.d("syb", "getWidth=" + yiew.width);
65 | int meature = meature(yiew.width);
66 | // Log.d("syb", "getWidth=" + meature);
67 | return meature;
68 | }
69 |
70 | public static int meature(String meature) {
71 | // Log.d("syb","line"+unit);
72 | // Log.d("syb","view"+view);
73 |
74 | if (meature == null || meature.equals("")) {
75 | return -2;
76 | }
77 |
78 | if (meature.equals("match") || meature.equals("match_parent")) {
79 | return -1;
80 | } else if (meature.equals("wrap") || meature.equals("wrap_content")) {
81 | return -2;
82 | } else {
83 |
84 | return meatureWithUnit(meature);
85 |
86 |
87 | }
88 |
89 | }
90 |
91 | public static int meatureWithUnit(String meature) {
92 | try {
93 | if (meature == null) {
94 | return 0;
95 | }
96 | Log.d("syb", "meatureWithUnit=" + meature);
97 | if (meature.endsWith("dp")) {
98 | String substring = meature.substring(0, meature.length() - 2);
99 | return Utils.dip2px(Integer.valueOf(substring));
100 | } else if (meature.endsWith("dip")) {
101 | String substring = meature.substring(0, meature.length() - 3);
102 | return Utils.dip2px(Integer.valueOf(substring));
103 | } else if (meature.endsWith("px")) {
104 | String substring = meature.substring(0, meature.length() - 2);
105 | return Integer.valueOf(substring);
106 | } else {
107 | return Utils.dip2px(Integer.valueOf(meature));
108 | }
109 | } catch (Exception e) {
110 | return -2;
111 | }
112 | }
113 |
114 |
115 | public static Object getValueInt(Class clazz, String varName) {
116 |
117 | java.lang.reflect.Field fieldRequested = null;
118 |
119 | try {
120 | fieldRequested = clazz.getField(varName);
121 | if (fieldRequested != null) {
122 | return fieldRequested.get(clazz);
123 | }
124 | } catch (SecurityException e) {
125 | e.printStackTrace();
126 | } catch (NoSuchFieldException e) {
127 | e.printStackTrace();
128 | } catch (IllegalAccessException e) {
129 | e.printStackTrace();
130 | } catch (IllegalArgumentException e) {
131 | e.printStackTrace();
132 | }
133 | return null;
134 | }
135 |
136 |
137 | public static int getDrawableId(Context context, String name) {
138 | return context.getResources().getIdentifier(name, "drawable", context.getPackageName());
139 | }
140 |
141 | /**
142 | * return the id (from the R.java autogenerated class) of the string that pass its name as argument
143 | */
144 | public static int getStringId(Context context, String name) {
145 | return context.getResources().getIdentifier(name, "string", context.getPackageName());
146 | }
147 |
148 | /**
149 | * convert densityPixel to pixel
150 | */
151 | public static float dpToPx(float dp) {
152 | return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, Resources.getSystem().getDisplayMetrics());
153 |
154 | }
155 |
156 | /**
157 | * convert scalePixel to pixel
158 | */
159 | public static float spToPx(float sp) {
160 | return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, Resources.getSystem().getDisplayMetrics());
161 | }
162 |
163 | /**
164 | * convert pixel to densityPixel
165 | */
166 | public static float pxToDp(int px) {
167 | return (px / Resources.getSystem().getDisplayMetrics().density);
168 | }
169 |
170 | /**
171 | * convert pixel to scaledDensityPixel
172 | */
173 | public static float pxToSp(int px) {
174 | return (px / Resources.getSystem().getDisplayMetrics().scaledDensity);
175 |
176 | }
177 |
178 | /**
179 | * convert densityPixel to scaledDensityPixel
180 | */
181 | public static float dpToSp(float dp) {
182 | return (int) (dpToPx(dp) / Resources.getSystem().getDisplayMetrics().scaledDensity);
183 | }
184 |
185 | /**
186 | * return device Width
187 | */
188 | public static int deviceWidth() {
189 | return Resources.getSystem().getDisplayMetrics().widthPixels;
190 | }
191 |
192 |
193 | public static boolean classExists(String className) {
194 | try {
195 | Class.forName(className);
196 | return true;
197 | } catch (ClassNotFoundException ex) {
198 | return false;
199 | }
200 | }
201 |
202 |
203 | private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
204 |
205 | public static int generateViewId() {
206 | for (; ; ) {
207 | final int result = sNextGeneratedId.get();
208 | // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
209 | int newValue = result + 1;
210 | if (newValue > 0x00FFFFFF) {
211 | newValue = 1; // Roll over to 1, not 0.
212 | }
213 | if (sNextGeneratedId.compareAndSet(result, newValue)) {
214 | return result;
215 | }
216 | }
217 | }
218 |
219 |
220 |
221 | public static int parseColor(String background) {
222 | if (background.startsWith("#")) {
223 | if (background.length() == 7 || background.length() == 9) {
224 | return Color.parseColor(background);
225 | } else if (background.length() == 4) {
226 | background += background.substring(1);
227 | return Color.parseColor(background);
228 | }
229 | if (background.length() == 5) {
230 | background += background.substring(1);
231 | return Color.parseColor(background);
232 | }
233 |
234 | }
235 |
236 | return 0;
237 | }
238 |
239 | public static String getValueStringIfDataExist(XViewBody yiew, String text, String defaultValue) {
240 |
241 | String keyname = text.substring(1);
242 | if (yiew.data != null) {
243 | String retValue = yiew.getData(keyname, defaultValue);
244 | return retValue;
245 | } else if (yiew.getRootComponet() != null && yiew.getRootComponet().data != null) {
246 | String retValue = yiew.getRootComponet().getData(keyname, defaultValue);
247 | return retValue;
248 | } else {
249 | return defaultValue;
250 | }
251 |
252 |
253 | }
254 |
255 | public static int getValueIntIfDataExist(XViewBody yiew, String text, int defaultValue) {
256 | if (text.startsWith("&")) {
257 | String keyname = text.substring(1);
258 | int data = yiew.getDataInt(keyname, defaultValue);
259 | return data;
260 | }
261 | return defaultValue;
262 | }
263 |
264 |
265 |
266 |
267 | }
268 |
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/XViewComponent.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 |
7 | import com.arthas.xjsonview.bean.XViewBody;
8 |
9 | public interface XViewComponent {
10 | View createComponentView(Context context, ViewGroup parent, XViewBody yiew);
11 |
12 | public void render(XViewBody yiew);
13 |
14 | }
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/XViewEngine.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 |
7 | import com.arthas.xjsonview.bean.XViewBody;
8 |
9 |
10 | /**
11 | * Created by zhangyn on 17/3/28.
12 | */
13 |
14 | public class XViewEngine {
15 |
16 |
17 | public static void addChild(Context context, ViewGroup view, XViewBody parentYiew) {
18 |
19 | if (parentYiew.child != null && parentYiew.child.size() > 0) {
20 | for (XViewBody child : parentYiew.child) {
21 |
22 | if (parentYiew.getYiewStore() != null) {
23 | child.setYiewStore(parentYiew.getYiewStore());
24 | }
25 | if (parentYiew.getRootComponet() != null) {
26 | child.setRootComponet(parentYiew.getRootComponet());
27 | }
28 | child.parentNode = parentYiew;
29 |
30 | View childView = createView(context, view, child);
31 | if (childView != null) {
32 | view.addView(childView);
33 | }
34 |
35 | }
36 | }
37 |
38 |
39 | }
40 |
41 |
42 | public static View createView(Context context, ViewGroup parent, XViewBody yiew) {
43 |
44 | if (yiew.getYiewStore() != null) {
45 | XViewComponent component = yiew.getYiewStore().findComponent(yiew.view);
46 | if (component != null) {
47 | View view = component.createComponentView(context, parent, yiew);
48 | return view;
49 | }
50 | }
51 |
52 | XViewComponent component = XiewConfig.findComponent(yiew.view);
53 | if (component != null) {
54 | View view = component.createComponentView(context, parent, yiew);
55 | return view;
56 | }
57 |
58 |
59 | return null;
60 | }
61 |
62 |
63 | // public static void invalid(Yiew yiewBean) {
64 | //
65 | // TextViewProcess.refresh(yiewBean);
66 | // }
67 |
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/XViewImageAdapter.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview;
2 |
3 | import android.widget.ImageView;
4 |
5 | import com.arthas.xjsonview.bean.XViewBase;
6 |
7 | /**
8 | * Created by zhangyn on 17/3/30.
9 | */
10 |
11 | public interface XViewImageAdapter {
12 | void display(ImageView view, String src, XViewBase yiew);
13 | }
14 |
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/XViewMain.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 |
6 | import com.arthas.xjsonview.bean.XView;
7 | import com.arthas.xjsonview.bean.XViewBody;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | * Created by zhangyn on 17/4/7.
13 | */
14 |
15 | public class XViewMain {
16 |
17 | public static View startProcess(Context context, XView yiewResp) {
18 |
19 | XViewStore yiewStore = new XViewStore();
20 | if ("AndroidLayout".equals(yiewResp.head.process)) {
21 | List components = yiewResp.head.components;
22 | if (components != null) {
23 | for (XViewBody xViewComponentBean : components) {
24 |
25 | SimpleXViewComponent yiewComponent = new SimpleXViewComponent(xViewComponentBean);
26 |
27 | ComponentManager.addSimpleXViewComponent(yiewResp,yiewComponent,yiewStore);
28 |
29 |
30 |
31 | }
32 | }
33 |
34 |
35 | yiewResp.template.setYiewStore(yiewStore);
36 |
37 |
38 | return XViewEngine.createView(context, null, yiewResp.template);
39 |
40 |
41 | }
42 |
43 | return null;
44 |
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/XViewStore.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview;
2 |
3 | import android.view.View;
4 |
5 | import com.arthas.xjsonview.bean.XViewBody;
6 |
7 | import java.util.HashMap;
8 |
9 | /**
10 | * Created by zhangyn on 17/4/5.
11 | */
12 | public class XViewStore {
13 |
14 |
15 | //有name的会缓存XView
16 | public HashMap yiews = new HashMap();
17 |
18 | private HashMap componentMap = null;
19 |
20 | public void addComponent(String name, XViewComponent line) {
21 | if (componentMap == null) {
22 | componentMap = new HashMap<>();
23 | }
24 | componentMap.put(name, line);
25 | }
26 |
27 | public XViewComponent findComponent(String view) {
28 |
29 | if (componentMap == null) {
30 | return null;
31 | }
32 | return componentMap.get(view);
33 | }
34 |
35 |
36 | public XViewBody getYiewByName(String name) {
37 | return yiews.get(name);
38 | }
39 |
40 | public void cacheNamedYiew(XViewBody yiew, View view) {
41 | yiew.setCurrentView(view);
42 | if (yiew.name != null) {
43 |
44 |
45 | yiew.id = Utils.generateViewId();
46 | view.setId(yiew.id);
47 | yiews.put(yiew.name, yiew);
48 |
49 | }
50 |
51 | // if (yiew.id != 0) {
52 | // putId(yiew.name, yiew.id);
53 | // }
54 |
55 |
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/XiewConfig.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview;
2 |
3 | import com.arthas.xjsonview.process.FrameLayoutProcess;
4 | import com.arthas.xjsonview.process.HorizonLayoutProcess;
5 | import com.arthas.xjsonview.process.ImageViewComponent;
6 | import com.arthas.xjsonview.process.RelativeLayoutProcess;
7 | import com.arthas.xjsonview.process.ScrollViewProcess;
8 | import com.arthas.xjsonview.process.SimpleViewProcess;
9 | import com.arthas.xjsonview.process.TextViewProcess;
10 | import com.arthas.xjsonview.process.VerticalLayoutProcess;
11 | import com.arthas.xjsonview.process.diy.ScrollComponent;
12 | import com.arthas.xjsonview.process.list.RecyclerViewComponent;
13 |
14 | import java.util.HashMap;
15 |
16 | /**
17 | * Created by zhangyn on 17/3/30.
18 | */
19 |
20 | public class XiewConfig {
21 |
22 |
23 | private static XViewImageAdapter imageAdapter;
24 | private static HashMap componentMap = new HashMap();
25 |
26 |
27 | public static void setImageAdapter(XViewImageAdapter imageAdapter) {
28 | XiewConfig.imageAdapter = imageAdapter;
29 | }
30 |
31 | public static XViewImageAdapter getImageAdapter() {
32 | return imageAdapter;
33 | }
34 |
35 |
36 | public static void addComponent(String name, XViewComponent line) {
37 | componentMap.put(name, line);
38 | }
39 |
40 | static {
41 |
42 |
43 | addComponent("verticalLayout", new VerticalLayoutProcess());
44 | addComponent("horizonLayout", new HorizonLayoutProcess());
45 |
46 | addComponent("ScrollView", new ScrollViewProcess());
47 | addComponent("scrollView", new ScrollComponent());
48 |
49 | addComponent("RelativeLayout", new RelativeLayoutProcess());
50 | addComponent("FrameLayout", new FrameLayoutProcess());
51 |
52 |
53 | addComponent("TextView", new TextViewProcess());
54 | addComponent("ImageView", new ImageViewComponent());
55 | addComponent("View", new SimpleViewProcess());
56 | addComponent("RecyclerView", new RecyclerViewComponent());
57 |
58 | }
59 |
60 | public static XViewComponent findComponent(String view) {
61 |
62 |
63 | // if ("scrollView".equals(view)) {
64 | // IComponent iComponent = componentMap.get(view);
65 | // if (iComponent == null) {
66 | // iComponent = new ScrollComponent();
67 | // componentMap.put(view, iComponent);
68 | // }
69 | // return iComponent;
70 | // }
71 | return componentMap.get(view);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/bean/PropertyBean.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview.bean;
2 |
3 | public class PropertyBean {
4 |
5 |
6 | public String name;
7 | public String type;
8 | public String value;
9 |
10 | public Class getClassType() {
11 | switch (type) {
12 | case "int":
13 | return int.class;
14 |
15 | case "long":
16 | return long.class;
17 | case "short":
18 | return short.class;
19 | case "float":
20 | return float.class;
21 | case "double":
22 | return double.class;
23 | case "boolean":
24 | return boolean.class;
25 |
26 | case "Integer":
27 | return Integer.class;
28 |
29 | case "Long":
30 | return Long.class;
31 | case "Short":
32 | return Short.class;
33 | case "Float":
34 | return Float.class;
35 |
36 | case "Double":
37 | return Double.class;
38 |
39 | case "Boolean":
40 | return Boolean.class;
41 |
42 |
43 | case "String":
44 | return String.class;
45 | case "Object":
46 | return Object.class;
47 |
48 | case "char":
49 | return char.class;
50 | case "Byte":
51 | return Byte.class;
52 | case "byte":
53 | return byte.class;
54 |
55 | default:
56 | // Log.d("syb", "Class.forName =" + type);
57 | Class> aClass = null;
58 | try {
59 | aClass = Class.forName(type);
60 | } catch (ClassNotFoundException e) {
61 | e.printStackTrace();
62 | }
63 | return aClass;
64 | }
65 |
66 | }
67 |
68 |
69 |
70 | public Object getValueClassType(Class classType) {
71 | if(classType == int.class){
72 | if(value.equals("")){
73 | return 0;
74 | }
75 | return Integer.parseInt(value);
76 | }else if(classType == short.class){
77 | if(value.equals("")){
78 | return 0;
79 | }
80 | return Short.parseShort(value);
81 | }else if(classType == byte.class){
82 | if(value.equals("")){
83 | return 0;
84 | }
85 | return Byte.parseByte(value);
86 | }else if(classType == double.class){
87 | if(value.equals("")){
88 | return 0;
89 | }
90 | return Double.parseDouble(value);
91 | }else if(classType == boolean.class){
92 | if(value.equals("")){
93 | return false;
94 | }
95 | return Boolean.parseBoolean(value);
96 | }else if(classType == float.class){
97 | if(value.equals("")){
98 | return 0;
99 | }
100 | return Float.parseFloat(value);
101 | }else if(classType == long.class){
102 | if(value.equals("")){
103 | return 0;
104 | }
105 | return Long.parseLong(value);
106 | }else {
107 | return classType.cast(value);
108 | }
109 | }
110 | }
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/bean/XView.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview.bean;
2 |
3 | /**
4 | * Created by zhangyn on 17/4/7.
5 | */
6 |
7 | public class XView {
8 |
9 | /**
10 | * head : {"process":"yiewEngine","component":[{"name":"group2","template":{"view":"RelativeLayout","width":"match","height":"48","background":"#ffffff","child":[{"name":"contact","view":"TextView","text":"联系人","textColor":"#666666","marginLeft":"24","textSize":"14","layout_centerVertical":true}]}}]}
11 | * template : {"view":"verticalLayout","width":"match","height":"match","background":"#f6f6f6","child":[{"view":"refreshBar"},{"view":"scrollView","width":"match","height":"match","child":[{"view":"group"},{"view":"group","background":"#fb9236","text":"自定义属性覆盖文字","textColor":"#fff"},{"view":"View","width":"match","height":"30dp"},{"view":"group","background":"#f6f6f6","text":"component事件"},{"view":"group","background":"#56b0f5","text":"事件,点击调用activity的showToast方法","textColor":"#fff","onClick":"showToast"},{"view":"group","background":"#f6f6f6","text":"普通事件"},{"name":"simpleEvent","onClick":"showToast","view":"RelativeLayout","width":"match","height":"48","background":"#d9Ff5858","paddingLeft":"16","paddingRight":"16","child":[{"view":"ImageView","src":"http://onpxz5rdd.bkt.clouddn.com/ic_service_black.png","width":"16dp","height":"16dp","layout_centerVertical":true},{"view":"TextView","text":"点击此处","textColor":"#444444","marginLeft":"24","textSize":"14","layout_centerVertical":true},{"view":"TextView","width":"wrap","text":">","textColor":"#444444","layout_alignParentRight":"true","layout_centerVertical":true}]},{"view":"group","background":"#f6f6f6","text":"application里,全局定义了一些component组件,查看代码便知"},{"view":"group","background":"#f6f6f6","text":"图片适配"},{"name":"imagePane","view":"horizonLayout","width":"match_parent","height":"wrap_content","background":"#ffffff","paddingLeft":"12dp","paddingRight":"12dp","paddingTop":"16","paddingBottom":"10dp","child":[{"view":"ImageView","src":"http://img.sanjiang.com/image/20173/1/image1488349927926.jpg","width":"74dp","height":"74dp","margin":"5dp"},{"view":"ImageView","src":"https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=232163874,2153671052&fm=58","width":"74dp","height":"74dp","margin":"5dp"},{"view":"ImageView","src":"https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=232163874,2153671052&fm=58","width":"74dp","height":"74dp","margin":"5dp"},{"view":"ImageView","src":"https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=232163874,2153671052&fm=58","width":"74dp","height":"74dp","margin":"5dp"}]}]}]}
12 | */
13 |
14 | public XViewHead head;
15 | public XViewBody template;
16 |
17 |
18 | public String scope;
19 | }
20 |
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/bean/XViewBase.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview.bean;
2 |
3 | import java.io.Serializable;
4 | import java.util.ArrayList;
5 |
6 | /**
7 | * Created by zhangyn on 17/3/29.
8 | */
9 |
10 |
11 | public class XViewBase implements Serializable {
12 | public String name;
13 |
14 | // view
15 | public String view;
16 | public String width;
17 | public String height;
18 |
19 | public int id;
20 | public String onClick;
21 | public String visibility;
22 |
23 | public String tag;
24 |
25 |
26 | // public ArrayList propertys;
27 | public ArrayList child;
28 |
29 |
30 |
31 | public String padding;
32 | public String paddingLeft;
33 | public String paddingTop;
34 | public String paddingRight;
35 | public String paddingBottom;
36 | public String margin;
37 | public String marginLeft;
38 | public String marginTop;
39 | public String marginRight;
40 | public String marginBottom;
41 |
42 | public String background;
43 | public String gravity;
44 |
45 | // linearlayout
46 | public String layout_gravity;
47 | public int weight;
48 |
49 |
50 | // textview
51 | public String text;
52 |
53 | public String textSize;
54 | public String textColor;
55 |
56 | public String hint;
57 | public int maxLine;
58 | public String hintColor;
59 |
60 | public String lineSpace;
61 |
62 | // imageview
63 | public String scaleType;
64 | public String src;
65 |
66 |
67 | //relativelayout
68 | public boolean layout_alignParentRight;
69 | public boolean layout_alignParentLeft;
70 | public boolean layout_alignParentTop;
71 | public boolean layout_alignParentBottom;
72 |
73 | public boolean layout_centerInParent;
74 | public boolean layout_centerHorizontal;
75 | public boolean layout_centerVertical;
76 |
77 |
78 |
79 |
80 |
81 |
82 | //advance
83 | public String alignBaseline;
84 | public String below;
85 | public String alignBottom;
86 | public String toLeftOf;
87 | public String toRightOf;
88 | public String above;
89 | public String alignLeft;
90 | public String alignRight;
91 | public String alignTop;
92 |
93 | //recyclerView
94 | public String itemLayout;
95 |
96 | // @Override
97 | // public String toString() {
98 | // return "YiewBean{" +
99 | // "view='" + view + '\'' +
100 | // ", width='" + width + '\'' +
101 | // ", height='" + height + '\'' +
102 | // ", id=" + id +
103 | // ", onClick='" + onClick + '\'' +
104 | // ", visibility='" + visibility + '\'' +
105 | // ", tag='" + tag + '\'' +
106 | // ", propertys=" + propertys +
107 | // ", child=" + child +
108 | // ", padding=" + padding +
109 | // ", paddingLeft=" + paddingLeft +
110 | // ", paddingTop=" + paddingTop +
111 | // ", paddingRight=" + paddingRight +
112 | // ", paddingBottom=" + paddingBottom +
113 | // ", margin=" + margin +
114 | // ", marginLeft=" + marginLeft +
115 | // ", marginTop=" + marginTop +
116 | // ", marginRight=" + marginRight +
117 | // ", marginBottom=" + marginBottom +
118 | // ", background='" + background + '\'' +
119 | // ", gravity='" + gravity + '\'' +
120 | // ", layout_gravity='" + layout_gravity + '\'' +
121 | // ", weight=" + weight +
122 | // ", text='" + text + '\'' +
123 | // ", textSize=" + textSize +
124 | // ", textColor='" + textColor + '\'' +
125 | // ", hint='" + hint + '\'' +
126 | // ", maxLine=" + maxLine +
127 | // ", hintColor='" + hintColor + '\'' +
128 | // ", lineSpace=" + lineSpace +
129 | // ", scaleType='" + scaleType + '\'' +
130 | // ", src='" + src + '\'' +
131 | // ", layout_alignParentRight=" + layout_alignParentRight +
132 | // ", layout_alignParentLeft=" + layout_alignParentLeft +
133 | // ", layout_alignParentTop=" + layout_alignParentTop +
134 | // ", layout_alignParentBottom=" + layout_alignParentBottom +
135 | // ", layout_centerInParent=" + layout_centerInParent +
136 | // ", layout_centerHorizontal=" + layout_centerHorizontal +
137 | // ", layout_centerVertical=" + layout_centerVertical +
138 | // ", layout_toLeftOf=" + layout_toLeftOf +
139 | // ", layout_toRightOf=" + layout_toRightOf +
140 | // ", layout_above=" + layout_above +
141 | // ", layout_below=" + layout_below +
142 | // ", layout_alignLeft=" + layout_alignLeft +
143 | // ", layout_alignRight=" + layout_alignRight +
144 | // ", layout_alignTop=" + layout_alignTop +
145 | // ", layout_alignBottom=" + layout_alignBottom +
146 | // ", layout_alignBaseline=" + layout_alignBaseline +
147 | // '}';
148 | // }
149 | }
150 |
151 |
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/bean/XViewBody.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview.bean;
2 |
3 | import com.arthas.xjsonview.Utils;
4 | import com.arthas.xjsonview.XViewComponent;
5 | import com.arthas.xjsonview.XViewStore;
6 | import com.arthas.xjsonview.XiewConfig;
7 |
8 | import java.io.ByteArrayInputStream;
9 | import java.io.ByteArrayOutputStream;
10 | import java.io.ObjectInputStream;
11 | import java.io.ObjectOutputStream;
12 | import java.io.Serializable;
13 | import java.util.ArrayList;
14 | import java.util.Map;
15 |
16 | /**
17 | * Created by zhangyn on 17/3/31.
18 | */
19 |
20 | public class XViewBody extends XViewBase implements Serializable {
21 |
22 | public static final String verticalLayout = "verticalLayout";
23 | public static final String horizonLayout = "horizonLayout";
24 |
25 | public static final String ScrollView = "ScrollView";
26 | public static final String scrollView = "scrollView";
27 |
28 | public static final String RelativeLayout = "RelativeLayout";
29 | public static final String FrameLayout = "FrameLayout";
30 |
31 |
32 | public static final String TextView = "TextView";
33 | public static final String ImageView = "ImageView";
34 | public static final String View = "View";
35 |
36 |
37 | @Override
38 | public String toString() {
39 | return "view=" + view;
40 | }
41 |
42 | public static final String MATCH = "match";
43 | public static final String WRAP = "wrap";
44 |
45 |
46 | public String getData(String key, String defaultValue) {
47 | if (data == null) {
48 | return defaultValue;
49 | } else {
50 | Object s = data.get(key);
51 | if (s == null) {
52 | return defaultValue;
53 | }
54 | return s.toString();
55 | }
56 | }
57 |
58 | public int getDataInt(String key, int defaultValue) {
59 | if (data == null) {
60 | return 0;
61 | } else {
62 | Object s = data.get(key);
63 | if (s == null) {
64 | return defaultValue;
65 | } else {
66 | try {
67 | int i = Integer.parseInt(s.toString());
68 | return i;
69 | } catch (Exception e) {
70 | return defaultValue;
71 | }
72 |
73 | }
74 |
75 | }
76 | }
77 |
78 | public Map getData() {
79 | return data;
80 | }
81 |
82 | public Map data;
83 |
84 |
85 |
86 | public transient XViewBody parentNode;
87 | private transient XViewBody rootComponet;
88 | private transient XViewStore yiewStore;
89 | private transient android.view.View currentView;
90 |
91 |
92 | public void setRootComponet(XViewBody rootComponet) {
93 | this.rootComponet = rootComponet;
94 | }
95 |
96 | public XViewBody getRootComponet() {
97 | return rootComponet;
98 | }
99 |
100 | public void setYiewStore(XViewStore yiewStore) {
101 | this.yiewStore = yiewStore;
102 | }
103 |
104 | public XViewStore getYiewStore() {
105 | return yiewStore;
106 | }
107 |
108 |
109 | public void addChild(XViewBody yiew) {
110 | if (child == null) {
111 | child = new ArrayList<>();
112 |
113 | }
114 | child.add(yiew);
115 | }
116 |
117 |
118 | public void removeAllYiew() {
119 |
120 | this.child.clear();
121 |
122 | }
123 |
124 |
125 |
126 |
127 | public T getCurrentView() {
128 | return (T) currentView;
129 | }
130 |
131 | public void setCurrentView(android.view.View currentView) {
132 | this.currentView = currentView;
133 | }
134 |
135 | public void invalid() {
136 |
137 | XViewComponent component = XiewConfig.findComponent(view);
138 | if (component != null) {
139 | component.render(this);
140 | }
141 |
142 | }
143 | //
144 |
145 | public static XViewBody create(String type, String width, String height) {
146 | XViewBody yiew = new XViewBody();
147 | yiew.view = type;
148 | yiew.width = width;
149 | yiew.height = height;
150 | return yiew;
151 | }
152 |
153 |
154 | public String getBackground() {
155 | if (background.startsWith("&")) {
156 | String a = Utils.getValueStringIfDataExist(this, background, null);
157 | return a;
158 | } else if (background != null) {
159 | return background;
160 | }
161 | return null;
162 | }
163 |
164 |
165 | public XViewBody deepClone() {
166 |
167 |
168 | try {
169 | ByteArrayOutputStream bo = new ByteArrayOutputStream();
170 | ObjectOutputStream oo = new ObjectOutputStream(bo);
171 | oo.writeObject(this);
172 | ByteArrayInputStream bi = new ByteArrayInputStream(bo.toByteArray());
173 | ObjectInputStream oi = new ObjectInputStream(bi);
174 | Object o = oi.readObject();
175 | oi.close();
176 | bi.close();
177 | return (XViewBody) o;
178 | } catch (Exception e) {
179 | e.printStackTrace();
180 | }
181 |
182 | return null;
183 |
184 | }
185 |
186 | public void setComponentTemplate(XViewBody template) {
187 |
188 | setRootComponet(this);
189 | XViewBody to = this;
190 | XViewBody from = template;
191 |
192 | to.view = from.view;
193 | to.child = from.child;
194 |
195 | if (to.name != null) {
196 | to.name = from.name;
197 | }
198 | if (to.id == 0) {
199 | to.id = from.id;
200 | }
201 | if (to.width == null) {
202 | to.width = from.width;
203 | }
204 | if (to.height == null) {
205 | to.height = from.height;
206 | }
207 |
208 | if (to.onClick == null) {
209 | to.onClick = from.onClick;
210 | }
211 | if (to.visibility == null) {
212 | to.visibility = from.visibility;
213 | }
214 | if (to.tag == null) {
215 | to.tag = from.tag;
216 | }
217 | if (to.padding == null) {
218 | to.padding = from.padding;
219 | }
220 | if (to.paddingLeft == null) {
221 | to.paddingLeft = from.paddingLeft;
222 | }
223 | if (to.paddingTop == null) {
224 | to.paddingTop = from.paddingTop;
225 | }
226 | if (to.paddingRight == null) {
227 | to.paddingRight = from.paddingRight;
228 | }
229 | if (to.paddingBottom == null) {
230 | to.paddingBottom = from.paddingBottom;
231 | }
232 | if (to.margin == null) {
233 | to.margin = from.margin;
234 | }
235 | if (to.marginLeft == null) {
236 | to.marginLeft = from.marginLeft;
237 | }
238 | if (to.marginTop == null) {
239 | to.marginTop = from.marginTop;
240 | }
241 | if (to.marginRight == null) {
242 | to.marginRight = from.marginRight;
243 | }
244 | if (to.marginBottom == null) {
245 | to.marginBottom = from.marginBottom;
246 | }
247 | if (to.background == null) {
248 | to.background = from.background;
249 | }
250 | if (to.gravity == null) {
251 | to.gravity = from.gravity;
252 | }
253 | if (to.layout_gravity == null) {
254 | to.layout_gravity = from.layout_gravity;
255 | }
256 | if (to.weight == 0) {
257 | to.weight = from.weight;
258 | }
259 | if (to.text == null) {
260 | to.text = from.text;
261 | }
262 | if (to.textSize == null) {
263 | to.textSize = from.textSize;
264 | }
265 | if (to.textColor == null) {
266 | to.textColor = from.textColor;
267 | }
268 | if (to.hint == null) {
269 | to.hint = from.hint;
270 | }
271 | if (to.maxLine == 0) {
272 | to.maxLine = from.maxLine;
273 | }
274 | if (to.hintColor == null) {
275 | to.hintColor = from.hintColor;
276 | }
277 | if (to.lineSpace == null) {
278 | to.lineSpace = from.lineSpace;
279 | }
280 | if (to.scaleType == null) {
281 | to.scaleType = from.scaleType;
282 | }
283 | if (to.src == null) {
284 | to.src = from.src;
285 | }
286 | if (!to.layout_alignParentRight) {
287 | to.layout_alignParentRight = from.layout_alignParentRight;
288 | }
289 | if (!to.layout_alignParentLeft) {
290 | to.layout_alignParentLeft = from.layout_alignParentLeft;
291 | }
292 | if (!to.layout_alignParentTop) {
293 | to.layout_alignParentTop = from.layout_alignParentTop;
294 | }
295 | if (!to.layout_alignParentBottom) {
296 | to.layout_alignParentBottom = from.layout_alignParentBottom;
297 | }
298 | if (!to.layout_centerInParent) {
299 | to.layout_centerInParent = from.layout_centerInParent;
300 | }
301 | if (!to.layout_centerHorizontal) {
302 | to.layout_centerHorizontal = from.layout_centerHorizontal;
303 | }
304 | if (!to.layout_centerVertical) {
305 | to.layout_centerVertical = from.layout_centerVertical;
306 | }
307 |
308 | if (to.alignBaseline == null) {
309 | to.alignBaseline = from.alignBaseline;
310 | }
311 | if (to.below == null) {
312 | to.below = from.below;
313 | }
314 | if (to.alignBottom == null) {
315 | to.alignBottom = from.alignBottom;
316 | }
317 | if (to.toLeftOf == null) {
318 | to.toLeftOf = from.toLeftOf;
319 | }
320 | if (to.toRightOf == null) {
321 | to.toRightOf = from.toRightOf;
322 | }
323 | if (to.above == null) {
324 | to.above = from.above;
325 | }
326 | if (to.alignLeft == null) {
327 | to.alignLeft = from.alignLeft;
328 | }
329 | if (to.alignRight == null) {
330 | to.alignRight = from.alignRight;
331 | }
332 | if (to.alignTop == null) {
333 | to.alignTop = from.alignTop;
334 | }
335 |
336 | }
337 | }
338 |
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/bean/XViewHead.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview.bean;
2 |
3 | import java.util.List;
4 |
5 | public class XViewHead {
6 |
7 |
8 | public String process;
9 | public List components;
10 |
11 |
12 | }
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/process/FrameLayoutProcess.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview.process;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.FrameLayout;
7 |
8 | import com.arthas.xjsonview.XViewComponent;
9 | import com.arthas.xjsonview.Utils;
10 | import com.arthas.xjsonview.bean.XViewBody;
11 | import com.arthas.xjsonview.process.base.LayoutProcess;
12 | import com.arthas.xjsonview.process.base.ViewGroupProcess;
13 | import com.arthas.xjsonview.process.base.ViewProcess;
14 |
15 | /**
16 | * Created by zhangyn on 17/4/5.
17 | */
18 |
19 | public class FrameLayoutProcess implements XViewComponent {
20 | public View createComponentView(Context context, ViewGroup parent, XViewBody yiew) {
21 | FrameLayout view = new FrameLayout(context);
22 |
23 | ViewGroup.LayoutParams params = Utils.createLayoutParams(parent, yiew);
24 | view.setLayoutParams(params);
25 |
26 | ViewProcess.applyView(view, yiew);
27 | LayoutProcess.applyaLayout(view, params, yiew);
28 |
29 | ViewGroupProcess.applyViewGroup(view,yiew);
30 |
31 | return view;
32 | }
33 |
34 | @Override
35 | public void render(XViewBody yiew) {
36 |
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/process/HorizonLayoutProcess.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview.process;
2 |
3 | import android.content.Context;
4 | import android.view.Gravity;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.LinearLayout;
8 |
9 | import com.arthas.xjsonview.XViewComponent;
10 | import com.arthas.xjsonview.Utils;
11 | import com.arthas.xjsonview.bean.XViewBody;
12 | import com.arthas.xjsonview.bean.XViewBase;
13 | import com.arthas.xjsonview.process.base.LayoutProcess;
14 | import com.arthas.xjsonview.process.base.ViewGroupProcess;
15 | import com.arthas.xjsonview.process.base.ViewProcess;
16 |
17 | import static com.arthas.xjsonview.Utils.getValueInt;
18 |
19 | /**
20 | * Created by zhangyn on 17/4/5.
21 | */
22 |
23 | public class HorizonLayoutProcess implements XViewComponent {
24 | public View createComponentView(Context context, ViewGroup parent, XViewBody yiew) {
25 |
26 | LinearLayout view = new LinearLayout(context);
27 | view.setOrientation(LinearLayout.HORIZONTAL);
28 | ViewGroup.LayoutParams params = Utils.createLayoutParams(parent, yiew);
29 | view.setLayoutParams(params);
30 |
31 | ViewProcess.applyView(view, yiew);
32 | LayoutProcess.applyaLayout(view, params, yiew);
33 |
34 | applyLinearLayout(view, yiew);
35 |
36 | ViewGroupProcess.applyViewGroup(view,yiew);
37 |
38 | return view;
39 | }
40 |
41 | @Override
42 | public void render(XViewBody yiew) {
43 |
44 | }
45 |
46 | public static void applyLinearLayout(LinearLayout view, XViewBase yiew) {
47 | if (yiew.gravity != null)
48 | view.setGravity((Integer) getValueInt(Gravity.class, yiew.gravity.toUpperCase()));
49 |
50 |
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/process/ImageViewComponent.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview.process;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.ImageView;
7 |
8 | import com.arthas.xjsonview.XViewComponent;
9 | import com.arthas.xjsonview.Utils;
10 | import com.arthas.xjsonview.XiewConfig;
11 | import com.arthas.xjsonview.bean.XViewBody;
12 | import com.arthas.xjsonview.process.base.LayoutProcess;
13 | import com.arthas.xjsonview.process.base.ViewProcess;
14 |
15 | /**
16 | * Created by zhangyn on 17/4/5.
17 | */
18 |
19 | public class ImageViewComponent implements XViewComponent {
20 | public View createComponentView(Context context, ViewGroup parent, XViewBody yiew) {
21 |
22 |
23 | ImageView view = new ImageView(context);
24 | ViewGroup.LayoutParams params = Utils.createLayoutParams(parent, yiew);
25 | view.setLayoutParams(params);
26 |
27 | ViewProcess.applyView(view, yiew);
28 | LayoutProcess.applyaLayout(view, params, yiew);
29 |
30 | applyImageView(view, yiew);
31 |
32 |
33 |
34 |
35 | return view;
36 | }
37 |
38 | @Override
39 | public void render(XViewBody yiew) {
40 |
41 | applyImageView((ImageView) yiew.getCurrentView(), yiew);
42 | }
43 |
44 |
45 | public static void applyImageView(ImageView view, XViewBody yiew) {
46 | if (view == null)
47 | {
48 | System.out.println();
49 | }
50 | // Log.d("syb", "yiew.src" + yiew.src);
51 | if (yiew.src != null) {
52 | if (yiew.src.startsWith("&")) {
53 | String src = Utils.getValueStringIfDataExist(yiew, yiew.src, null);
54 | if (src != null) {
55 | yiew.src =src;
56 | XiewConfig.getImageAdapter().display(view,src, yiew);
57 | }
58 | }else{
59 | XiewConfig.getImageAdapter().display(view, yiew.src, yiew);
60 | }
61 |
62 |
63 |
64 |
65 | }
66 |
67 |
68 |
69 | if (yiew.scaleType != null)
70 | view.setScaleType(ImageView.ScaleType.valueOf(yiew.scaleType));
71 | else
72 | view.setScaleType(ImageView.ScaleType.FIT_XY);
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/process/RelativeLayoutProcess.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview.process;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.RelativeLayout;
7 |
8 | import com.arthas.xjsonview.XViewComponent;
9 | import com.arthas.xjsonview.Utils;
10 | import com.arthas.xjsonview.bean.XViewBody;
11 | import com.arthas.xjsonview.process.base.LayoutProcess;
12 | import com.arthas.xjsonview.process.base.ViewGroupProcess;
13 | import com.arthas.xjsonview.process.base.ViewProcess;
14 |
15 | /**
16 | * Created by zhangyn on 17/4/5.
17 | */
18 |
19 | public class RelativeLayoutProcess implements XViewComponent {
20 | public View createComponentView(Context context, ViewGroup parent, XViewBody yiew ) {
21 |
22 | RelativeLayout view = new RelativeLayout(context);
23 |
24 | ViewGroup.LayoutParams params = Utils.createLayoutParams(parent, yiew);
25 | view.setLayoutParams(params);
26 |
27 | ViewProcess.applyView(view, yiew);
28 | LayoutProcess.applyaLayout(view, params, yiew);
29 |
30 |
31 | ViewGroupProcess.applyViewGroup(view,yiew);
32 |
33 |
34 | return view;
35 | }
36 |
37 | @Override
38 | public void render(XViewBody yiew) {
39 |
40 |
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/process/ScrollViewProcess.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview.process;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.ScrollView;
7 |
8 | import com.arthas.xjsonview.XViewComponent;
9 | import com.arthas.xjsonview.Utils;
10 | import com.arthas.xjsonview.bean.XViewBody;
11 | import com.arthas.xjsonview.process.base.LayoutProcess;
12 | import com.arthas.xjsonview.process.base.ViewGroupProcess;
13 | import com.arthas.xjsonview.process.base.ViewProcess;
14 |
15 | /**
16 | * Created by zhangyn on 17/4/5.
17 | */
18 |
19 | public class ScrollViewProcess implements XViewComponent {
20 | public View createComponentView(Context context, ViewGroup parent, XViewBody yiew) {
21 | ScrollView view = new ScrollView(context);
22 |
23 | ViewGroup.LayoutParams params = Utils.createLayoutParams(parent, yiew);
24 | view.setLayoutParams(params);
25 |
26 | view.setVerticalFadingEdgeEnabled(false);
27 | view.setOverScrollMode(ScrollView.OVER_SCROLL_NEVER);
28 | view.setFadingEdgeLength(0);
29 | ViewProcess.applyView(view, yiew);
30 | LayoutProcess.applyaLayout(view, params, yiew);
31 |
32 |
33 | view.setVerticalFadingEdgeEnabled(false);
34 | view.setOverScrollMode(ScrollView.OVER_SCROLL_NEVER);
35 | view.setFadingEdgeLength(0);
36 |
37 | ViewGroupProcess.applyViewGroup(view,yiew);
38 |
39 | return view;
40 |
41 | }
42 |
43 | @Override
44 | public void render(XViewBody yiew) {
45 |
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/process/SimpleViewProcess.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview.process;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 |
7 | import com.arthas.xjsonview.XViewComponent;
8 | import com.arthas.xjsonview.Utils;
9 | import com.arthas.xjsonview.bean.XViewBody;
10 | import com.arthas.xjsonview.process.base.LayoutProcess;
11 | import com.arthas.xjsonview.process.base.ViewProcess;
12 |
13 | /**
14 | * Created by zhangyn on 17/4/5.
15 | */
16 | public class SimpleViewProcess implements XViewComponent {
17 | public View createYiew(Context context, ViewGroup parent, XViewBody yiew) {
18 |
19 | View view = new View(context);
20 | ViewGroup.LayoutParams params = Utils.createLayoutParams(parent, yiew);
21 | view.setLayoutParams(params);
22 |
23 | ViewProcess.applyView(view, yiew);
24 | LayoutProcess.applyaLayout(view, params, yiew);
25 |
26 |
27 |
28 | return view;
29 | }
30 |
31 | @Override
32 | public View createComponentView(Context context, ViewGroup parent, XViewBody yiew) {
33 | return null;
34 | }
35 |
36 | @Override
37 | public void render(XViewBody yiew) {
38 |
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/process/TextViewProcess.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview.process;
2 |
3 | import android.content.Context;
4 | import android.util.TypedValue;
5 | import android.view.Gravity;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.TextView;
9 |
10 | import com.arthas.xjsonview.XViewComponent;
11 | import com.arthas.xjsonview.Utils;
12 | import com.arthas.xjsonview.bean.XViewBody;
13 | import com.arthas.xjsonview.process.base.LayoutProcess;
14 | import com.arthas.xjsonview.process.base.ViewProcess;
15 |
16 | /**
17 | * Created by zhangyn on 17/4/5.
18 | */
19 |
20 | public class TextViewProcess implements XViewComponent {
21 | public View createComponentView(Context context, ViewGroup parent, XViewBody yiew) {
22 | TextView view = new TextView(context);
23 | ViewGroup.LayoutParams params = Utils.createLayoutParams(parent, yiew);
24 | view.setLayoutParams(params);
25 |
26 |
27 |
28 |
29 | ViewProcess.applyView(view, yiew);
30 | LayoutProcess.applyaLayout(view, params, yiew);
31 |
32 | applyTextView(view, yiew);
33 |
34 |
35 | return view;
36 | }
37 |
38 | @Override
39 | public void render(XViewBody yiew) {
40 | applyTextView((TextView) yiew.getCurrentView(), yiew);
41 | }
42 |
43 | // public static View refresh(Yiew yiew) {
44 | //// View view = yiew.getCurrentView();
45 | //// ViewGroup.LayoutParams params = view.getLayoutParams();
46 | ////
47 | //// ViewProcess.applyView(view, yiew);
48 | //// LayoutProcess.applyaLayout(view, params, yiew);
49 | ////
50 | //// applyTextView(view, yiew);
51 | //
52 | //
53 | // return view;
54 | // }
55 |
56 | public static void applyTextView(TextView view, XViewBody yiew) {
57 |
58 | if (yiew.parentNode != null) {
59 | // if (yiew.textSize == null) {
60 | // yiew.textSize = yiew.parentNode.textSize;
61 | // }
62 | // if (yiew.textColor == null) {
63 | // yiew.textColor = yiew.parentNode.textColor;
64 | // }
65 | // if (yiew.maxLine == 0) {
66 | // yiew.maxLine = yiew.parentNode.maxLine;
67 | // }
68 | // if (yiew.hintColor == null) {
69 | // yiew.hintColor = yiew.parentNode.hintColor;
70 | // }
71 | // if (yiew.lineSpace == null) {
72 | // yiew.lineSpace = yiew.parentNode.lineSpace;
73 | // }
74 |
75 | // if (yiew.text == null)
76 | // yiew.text = yiew.parentNode.text;
77 | //
78 | // if (yiew.hint == null)
79 | // yiew.hint = yiew.parentNode.hint;
80 |
81 | }
82 |
83 |
84 | if (yiew.text != null) {
85 |
86 | if (yiew.text.startsWith("&")) {
87 |
88 | String a = Utils.getValueStringIfDataExist(yiew, yiew.text, yiew.text);
89 | view.setText(a);
90 | } else {
91 | view.setText(yiew.text);
92 | }
93 | }
94 |
95 |
96 | if (yiew.textColor != null) {
97 | if (yiew.textColor.startsWith("&")) {
98 | String textColor = Utils.getValueStringIfDataExist(yiew, yiew.textColor, null);
99 | if (textColor != null) {
100 | view.setTextColor(Utils.parseColor(textColor));
101 | }
102 | } else {
103 | view.setTextColor(Utils.parseColor(yiew.textColor));
104 | }
105 |
106 |
107 | }
108 | if (yiew.textSize != null) {
109 |
110 | if (yiew.textSize.startsWith("&")) {
111 | String a = Utils.getValueStringIfDataExist(yiew, yiew.textSize, null);
112 | if (a != null) {
113 | int textSize = Integer.parseInt(a.trim());
114 | view.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
115 | }
116 | } else {
117 | int textSize = Integer.parseInt(yiew.textSize.trim());
118 |
119 | view.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
120 | }
121 |
122 |
123 | }
124 | if (yiew.hint != null) {
125 | view.setHint(yiew.hint);
126 | }
127 | if (yiew.maxLine != 0) {
128 | view.setMaxLines(yiew.maxLine);
129 | }
130 | if (yiew.hintColor != null) {
131 | view.setHintTextColor(Utils.parseColor(yiew.hintColor));
132 | }
133 | if (yiew.lineSpace != null) {
134 | view.setLineSpacing(Utils.meature(yiew.lineSpace), 1);
135 | }
136 |
137 | if (yiew.gravity != null) {
138 | view.setGravity((Integer) Utils.getValueInt(Gravity.class, yiew.gravity.toUpperCase()));
139 | }
140 |
141 |
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/process/VerticalLayoutProcess.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview.process;
2 |
3 | import android.content.Context;
4 | import android.view.Gravity;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.LinearLayout;
8 |
9 | import com.arthas.xjsonview.XViewComponent;
10 | import com.arthas.xjsonview.Utils;
11 | import com.arthas.xjsonview.bean.XViewBody;
12 | import com.arthas.xjsonview.bean.XViewBase;
13 | import com.arthas.xjsonview.process.base.LayoutProcess;
14 | import com.arthas.xjsonview.process.base.ViewGroupProcess;
15 | import com.arthas.xjsonview.process.base.ViewProcess;
16 |
17 | import static com.arthas.xjsonview.Utils.getValueInt;
18 |
19 | /**
20 | * Created by zhangyn on 17/4/5.
21 | */
22 | public class VerticalLayoutProcess implements XViewComponent {
23 | public View createComponentView(Context context, ViewGroup parent, XViewBody yiew) {
24 |
25 | LinearLayout view = new LinearLayout(context);
26 | view.setOrientation(LinearLayout.VERTICAL);
27 |
28 | ViewGroup.LayoutParams params = Utils.createLayoutParams(parent, yiew);
29 | view.setLayoutParams(params);
30 |
31 |
32 |
33 | ViewProcess.applyView(view, yiew);
34 | LayoutProcess.applyaLayout(view, params, yiew);
35 |
36 | applyLinearLayout(view, yiew);
37 |
38 | ViewGroupProcess.applyViewGroup(view,yiew);
39 |
40 | return view;
41 |
42 | }
43 |
44 | public static void applyLinearLayout(LinearLayout view, XViewBase yiew) {
45 | if (yiew.gravity != null)
46 | view.setGravity((Integer) getValueInt(Gravity.class, yiew.gravity.toUpperCase()));
47 |
48 |
49 | }
50 |
51 | public void render(XViewBody yiew) {
52 |
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/process/base/LayoutProcess.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview.process.base;
2 |
3 | import android.view.Gravity;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.FrameLayout;
7 | import android.widget.LinearLayout;
8 | import android.widget.RelativeLayout;
9 |
10 | import com.arthas.xjsonview.Utils;
11 | import com.arthas.xjsonview.bean.XViewBody;
12 |
13 | /**
14 | * Created by zhangyn on 17/4/1.
15 | */
16 |
17 | public class LayoutProcess {
18 |
19 | public static void applyaLayout(View view, ViewGroup.LayoutParams params, XViewBody yiew) {
20 | if (params instanceof ViewGroup.MarginLayoutParams) {
21 | ViewGroup.MarginLayoutParams p = ((ViewGroup.MarginLayoutParams) params);
22 | // Log.d("syb", "yiew.margin = " + yiew.margin);
23 | if (yiew.margin != null) {
24 | int margin = Utils.meatureWithUnit(yiew.margin);
25 | p.setMargins(margin, margin, margin, margin);
26 | // Log.d("syb", "p.setMargins1 = " + margin);
27 | } else {
28 | p.setMargins(Utils.meatureWithUnit(yiew.marginLeft), Utils.meatureWithUnit(yiew.marginTop), Utils.meatureWithUnit(yiew.marginRight), Utils.meatureWithUnit(yiew.marginBottom));
29 | // Log.d("syb", "p.setMargins2 = " + Utils.meatureWithUnit(yiew.marginTop));
30 | }
31 | }
32 |
33 | if (params instanceof LinearLayout.LayoutParams) {
34 | LinearLayout.LayoutParams params1 = (LinearLayout.LayoutParams) params;
35 | if (yiew.layout_gravity != null)
36 | params1.gravity = (int) Utils.getValueInt(Gravity.class, yiew.layout_gravity.toUpperCase());
37 | if (yiew.weight != 0)
38 | params1.weight = yiew.weight;
39 |
40 | } else if (params instanceof RelativeLayout.LayoutParams) {
41 | RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) params;
42 | // params1.addRule(RelativeLayout.LEFT_OF, yiew.layout_toLeftOf);
43 | if (yiew.layout_alignParentLeft)
44 | params1.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
45 |
46 | if (yiew.layout_alignParentTop)
47 | params1.addRule(RelativeLayout.ALIGN_PARENT_TOP);
48 |
49 | if (yiew.layout_alignParentRight)
50 | params1.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
51 |
52 | if (yiew.layout_alignParentBottom)
53 | params1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
54 |
55 |
56 | if (yiew.layout_centerInParent)
57 | params1.addRule(RelativeLayout.CENTER_IN_PARENT);
58 |
59 | if (yiew.layout_centerHorizontal)
60 | params1.addRule(RelativeLayout.CENTER_HORIZONTAL);
61 |
62 | if (yiew.layout_centerVertical)
63 | params1.addRule(RelativeLayout.CENTER_VERTICAL);
64 |
65 |
66 |
67 |
68 | if (yiew.below != null) {
69 |
70 | int advanceId = getAdvanceId(yiew.below,yiew);
71 | if (advanceId != 0)
72 | {
73 | params1.addRule(RelativeLayout.BELOW, advanceId);
74 | }
75 |
76 | }
77 | if (yiew.toLeftOf != null) {
78 |
79 | int advanceId = getAdvanceId(yiew.toLeftOf,yiew);
80 | if (advanceId != 0)
81 | params1.addRule(RelativeLayout.LEFT_OF, advanceId);
82 | }
83 |
84 | if (yiew.toRightOf != null) {
85 |
86 | int advanceId = getAdvanceId(yiew.toRightOf,yiew);
87 | if (advanceId != 0)
88 | params1.addRule(RelativeLayout.RIGHT_OF, advanceId);
89 | }
90 |
91 | if (yiew.above != null) {
92 |
93 | int advanceId = getAdvanceId(yiew.above,yiew);
94 | if (advanceId != 0)
95 | params1.addRule(RelativeLayout.ABOVE, advanceId);
96 | }
97 |
98 | if (yiew.alignLeft != null) {
99 |
100 | int advanceId = getAdvanceId(yiew.alignLeft,yiew);
101 | if (advanceId != 0)
102 | params1.addRule(RelativeLayout.ALIGN_LEFT, advanceId);
103 | }
104 | if (yiew.alignRight != null) {
105 |
106 | int advanceId = getAdvanceId(yiew.alignRight,yiew);
107 | if (advanceId != 0)
108 | params1.addRule(RelativeLayout.ALIGN_RIGHT, advanceId);
109 | }
110 | if (yiew.alignTop != null) {
111 |
112 | int advanceId = getAdvanceId(yiew.alignTop,yiew);
113 | if (advanceId != 0)
114 | params1.addRule(RelativeLayout.ALIGN_TOP, advanceId);
115 | }
116 | if (yiew.alignBottom != null) {
117 |
118 | int advanceId = getAdvanceId(yiew.alignBottom,yiew);
119 | if (advanceId != 0)
120 | params1.addRule(RelativeLayout.ALIGN_BOTTOM, advanceId);
121 | }
122 | if (yiew.alignBaseline != null) {
123 |
124 | int advanceId = getAdvanceId(yiew.alignBaseline,yiew);
125 | if (advanceId != 0)
126 | params1.addRule(RelativeLayout.ALIGN_BASELINE, advanceId);
127 | }
128 |
129 |
130 |
131 |
132 | } else if (params instanceof FrameLayout.LayoutParams) {
133 | FrameLayout.LayoutParams params1 = (FrameLayout.LayoutParams) params;
134 | if (yiew.layout_gravity != null)
135 | params1.gravity = (int) Utils.getValueInt(Gravity.class, yiew.layout_gravity.toUpperCase());
136 |
137 |
138 | }
139 |
140 |
141 | }
142 |
143 | private static int getAdvanceId(String verb,XViewBody yiew) {
144 | if (verb.startsWith("#")) {
145 | int id = Integer.parseInt(verb.substring(1));
146 |
147 | return id;
148 | } else if (verb.startsWith("@")) {
149 | String name = verb.substring(1);
150 | XViewBody aa = yiew.getYiewStore().getYiewByName(name);
151 | if (aa != null) {
152 | return aa.id;
153 | }
154 | }
155 | return 0;
156 | }
157 | }
158 |
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/process/base/ViewGroupProcess.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview.process.base;
2 |
3 | import android.view.View;
4 | import android.view.ViewGroup;
5 |
6 | import com.arthas.xjsonview.XViewEngine;
7 | import com.arthas.xjsonview.bean.XViewBody;
8 |
9 | /**
10 | * Created by zhangyn on 17/4/1.
11 | */
12 |
13 | public class ViewGroupProcess {
14 | public static void applyViewGroup(final View viewGroup, final XViewBody yiew) {
15 |
16 | if (viewGroup instanceof ViewGroup && yiew.child != null && yiew.child.size() > 0) {
17 | ViewGroup group = (ViewGroup) viewGroup;
18 | XViewEngine.addChild(group.getContext(), group, yiew);
19 | }
20 |
21 |
22 | }
23 |
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/process/base/ViewProcess.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview.process.base;
2 |
3 | import android.content.Context;
4 | import android.util.Log;
5 | import android.view.View;
6 |
7 | import com.arthas.xjsonview.Utils;
8 | import com.arthas.xjsonview.bean.XViewBody;
9 |
10 | import java.lang.reflect.Method;
11 |
12 | /**
13 | * Created by zhangyn on 17/4/1.
14 | */
15 |
16 | public class ViewProcess {
17 | public static void applyView(final View view, final XViewBody yiew) {
18 |
19 |
20 | if (yiew.getYiewStore() != null) {
21 | yiew.getYiewStore().cacheNamedYiew(yiew, view);
22 | }
23 |
24 |
25 | if (yiew.id != 0) {
26 | view.setId(yiew.id);
27 |
28 | }
29 | render(view, yiew);
30 |
31 |
32 | // applyProperties(view, yiew);
33 |
34 | }
35 |
36 | public static void render(View view, final XViewBody yiew) {
37 | if (yiew.tag != null) {
38 | view.setTag(yiew.tag);
39 | }
40 | if (yiew.padding != null) {
41 |
42 | int padding = Utils.meatureWithUnit(yiew.padding);
43 | view.setPadding(padding, padding, padding, padding);
44 | } else {
45 | view.setPadding(Utils.meatureWithUnit(yiew.paddingLeft), Utils.meatureWithUnit(yiew.paddingTop), Utils.meatureWithUnit(yiew.paddingRight), Utils.meatureWithUnit(yiew.paddingBottom));
46 | }
47 | if (yiew.background != null) {
48 | String background = yiew.getBackground();
49 | // Log.d("syb","background="+background);
50 | if (background != null) {
51 | view.setBackgroundColor(Utils.parseColor(background));
52 | }
53 |
54 | }
55 |
56 |
57 | if (yiew.onClick != null) {
58 |
59 | view.setOnClickListener(new View.OnClickListener() {
60 | @Override
61 | public void onClick(View v) {
62 |
63 | Context context = v.getContext();
64 | try {
65 | Method myClick = context.getClass().getMethod(yiew.onClick);
66 | myClick.invoke(context);
67 | } catch (Exception e) {
68 |
69 | }
70 | try {
71 | Method myClick2 = context.getClass().getMethod(yiew.onClick, XViewBody.class);
72 | myClick2.invoke(context, yiew);
73 | } catch (Exception e) {
74 |
75 | }
76 |
77 |
78 | }
79 | }
80 | );
81 |
82 | }
83 | if (yiew.visibility != null) {
84 |
85 | String visibility = null;
86 | if (yiew.visibility.startsWith("&")) {
87 | visibility = Utils.getValueStringIfDataExist(yiew, yiew.visibility, "visible");
88 | } else {
89 | visibility = yiew.visibility;
90 | }
91 | Log.d("syb", "yiew.visibility2 = " + yiew.visibility);
92 | switch (visibility) {
93 | case "gone": {
94 | view.setVisibility(View.GONE);
95 | }
96 | break;
97 | case "visible": {
98 | view.setVisibility(View.VISIBLE);
99 | }
100 | break;
101 | case "invisible": {
102 | view.setVisibility(View.INVISIBLE);
103 | }
104 | break;
105 | }
106 | }
107 | }
108 |
109 |
110 | // public static void applyProperties(View view, YiewBean yiew) {
111 | // List propertys = yiew.propertys;
112 | // Log.d("syb", "set property" + propertys);
113 | // if (propertys != null && propertys.size() > 0) {
114 | // Class extends View> aClass = view.getClass();
115 | // Log.d("syb", " aClass =" + aClass);
116 | // for (PropertyBean propertyBean : propertys) {
117 | // String name = propertyBean.name;
118 | //
119 | //
120 | // String methodName = "set" + name.substring(0, 1).toUpperCase() + name.substring(1);
121 | // Log.d("syb", "set method = " + methodName);
122 | // try {
123 | //
124 | // Class classType = propertyBean.getClassType();
125 | // Method method = aClass.getMethod(methodName, classType);
126 | // method.invoke(view, propertyBean.getValueClassType(classType));
127 | // } catch (Exception e) {
128 | // e.printStackTrace();
129 | // Log.d("syb", "e" + e);
130 | // }
131 | // }
132 | // }
133 | //
134 | //
135 | // }
136 | }
137 |
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/process/diy/ScrollComponent.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview.process.diy;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 |
7 | import com.arthas.xjsonview.XViewComponent;
8 | import com.arthas.xjsonview.XViewEngine;
9 | import com.arthas.xjsonview.bean.XViewBody;
10 |
11 | /**
12 | * Created by zhangyn on 17/4/5.
13 | */
14 |
15 | public class ScrollComponent implements XViewComponent {
16 |
17 | @Override
18 | public View createComponentView(Context context, ViewGroup parent, XViewBody yiew) {
19 | XViewBody yiscroll = XViewBody.create(XViewBody.ScrollView, XViewBody.MATCH, XViewBody.MATCH);
20 | XViewBody verlayout = XViewBody.create(XViewBody.verticalLayout, XViewBody.MATCH, XViewBody.MATCH);
21 | yiscroll.addChild(verlayout);
22 | verlayout.child = yiew.child;
23 | yiew.child = null;
24 |
25 | yiew.setComponentTemplate(yiscroll);
26 | ViewGroup view = (ViewGroup) XViewEngine.createView(context, parent, yiew);
27 |
28 |
29 | return view;
30 | }
31 |
32 | @Override
33 | public void render(XViewBody yiew) {
34 |
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/process/list/RecyclerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview.process.list;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.NonNull;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | import com.arthas.xjsonview.XViewComponent;
11 | import com.arthas.xjsonview.XViewEngine;
12 | import com.arthas.xjsonview.bean.XViewBody;
13 |
14 | import java.util.ArrayList;
15 | import java.util.List;
16 |
17 | /**
18 | * Created by jianghejie on 15/8/8.
19 | */
20 | public abstract class RecyclerAdapter extends RecyclerView.Adapter implements
21 | View.OnClickListener {
22 |
23 | protected final Context context;
24 | private final XViewBody recyclerX;
25 |
26 |
27 | protected List data;
28 | private OnItemClickListener mOnItemClickListener = null;
29 | protected LayoutInflater layoutInflater;
30 |
31 | // /**
32 | // * Create a QuickAdapter.
33 | // *
34 | // * @param context The context.
35 | // * @param body The layout resource id of each item.
36 | // */
37 | // public RecyclerAdapter(Context context, XViewBody body)
38 | // {
39 | // this(context, body, null);
40 | // }
41 |
42 | /**
43 | * Same as QuickAdapter#QuickAdapter(Context,int) but with
44 | * some initialization data.
45 | *
46 | * @param context The context.
47 | * @param data A new list is created out of this one to avoid mutable list
48 | */
49 | public RecyclerAdapter(Context context, XViewBody recyclerX, List data) {
50 | this.data = data == null ? new ArrayList() : data;
51 | this.context = context;
52 | this.recyclerX = recyclerX;
53 | layoutInflater = LayoutInflater.from(context);
54 | }
55 |
56 | public List getData() {
57 | return data;
58 | }
59 |
60 | public void setData(List data) {
61 | this.data = data;
62 | notifyDataSetChanged();
63 | }
64 |
65 | public void clear() {
66 | this.data = null;
67 | notifyDataSetChanged();
68 | }
69 |
70 | public void addData(List data) {
71 | if (this.data == null) {
72 | setData(data);
73 | } else {
74 | this.data.addAll(data);
75 | notifyDataSetChanged();
76 | }
77 |
78 | }
79 |
80 | public void removeData(int position) {
81 | if (data != null) {
82 | this.data.remove(position);
83 | }
84 |
85 | }
86 |
87 | @Override
88 | public int getItemCount() {
89 | if (data == null) {
90 | return 0;
91 | }
92 | return data.size();
93 | }
94 |
95 | public T getItem(int position) {
96 | if (position >= data.size()) {
97 | return null;
98 | }
99 | return data.get(position);
100 | }
101 |
102 | public T getItem(AdapterHelper adapterHelper) {
103 | return data.get(adapterHelper.getDataPosition());
104 | }
105 |
106 | int i=0;
107 | @Override
108 | public AdapterHelper onCreateViewHolder(ViewGroup viewGroup, int viewType) {
109 | XViewBody child = (XViewBody) data.get(i);
110 |
111 | i++;
112 |
113 | // XViewComponent component = recyclerX.getYiewStore().findComponent(recyclerX.itemLayout);
114 |
115 | // View view = component.createComponentView(viewGroup.getContext(),viewGroup, null);
116 |
117 | View view = XViewEngine.createView(context, viewGroup, child);
118 | view.setOnClickListener(this);
119 | AdapterHelper vh = getAdapterHelper(view);
120 | return vh;
121 | }
122 |
123 | @NonNull
124 | public AdapterHelper getAdapterHelper(View view) {
125 | return new AdapterHelper(view);
126 | }
127 |
128 | @Override
129 | public void onBindViewHolder(AdapterHelper helper, int position) {
130 | helper.itemView.setTag(position);
131 | // XViewComponent component = body.getYiewStore().findComponent(body.itemLayout);
132 | // component.render();
133 | XViewBody item = (XViewBody) getItem(position);
134 |
135 | XViewComponent component = recyclerX.getYiewStore().findComponent(recyclerX.itemLayout);
136 | component.render(item);
137 | }
138 |
139 | /**
140 | * Implement this method and use the helper to adapt the view to the given item.
141 | *
142 | * @param helper A fully initialized helper.
143 | * @param item The item that needs to be displayed.
144 | * @param position
145 | */
146 | protected abstract void convert(AdapterHelper helper, T item, int position);
147 |
148 | @Override
149 | public void onClick(View v) {
150 | if (mOnItemClickListener != null) {
151 | mOnItemClickListener.onItemClick(v, (int) v.getTag());
152 | }
153 | }
154 |
155 | public void setOnItemClickListener(OnItemClickListener listener) {
156 | this.mOnItemClickListener = listener;
157 | }
158 |
159 | //define interface
160 | public static interface OnItemClickListener {
161 | void onItemClick(View view, int position);
162 | }
163 |
164 | }
--------------------------------------------------------------------------------
/XJsonViewLib/src/main/java/com/arthas/xjsonview/process/list/RecyclerViewComponent.java:
--------------------------------------------------------------------------------
1 | package com.arthas.xjsonview.process.list;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.LinearLayoutManager;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import com.arthas.xjsonview.SimpleXViewComponent;
10 | import com.arthas.xjsonview.Utils;
11 | import com.arthas.xjsonview.XViewComponent;
12 | import com.arthas.xjsonview.bean.XViewBody;
13 | import com.arthas.xjsonview.process.base.LayoutProcess;
14 | import com.arthas.xjsonview.process.base.ViewProcess;
15 |
16 | import java.util.ArrayList;
17 | import java.util.Map;
18 |
19 | /**
20 | * Created by zhangyn on 17/4/5.
21 | */
22 | public class RecyclerViewComponent implements XViewComponent {
23 | public View createComponentView(Context context, ViewGroup parent, XViewBody recyclerX) {
24 |
25 | RecyclerView recyclerView = new RecyclerView(context);
26 | recyclerView.setHasFixedSize(true);
27 | LinearLayoutManager mLayoutManager = new LinearLayoutManager(context);
28 | mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
29 | recyclerView.setLayoutManager(mLayoutManager);
30 |
31 |
32 | ViewGroup.LayoutParams params = Utils.createLayoutParams(parent, recyclerX);
33 | recyclerView.setLayoutParams(params);
34 |
35 |
36 |
37 | ViewProcess.applyView(recyclerView, recyclerX);
38 | LayoutProcess.applyaLayout(recyclerView, params, recyclerX);
39 | Map data = recyclerX.data;
40 | ArrayList