├── .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 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 list = (ArrayList) data.get("list"); 41 | 42 | 43 | // String itemLayout = recycler.itemLayout; 44 | SimpleXViewComponent component = (SimpleXViewComponent) recyclerX.getYiewStore().findComponent(recyclerX.itemLayout); 45 | XViewBody template = component.getTemplate(); 46 | 47 | ArrayList childs = new ArrayList<>(); 48 | 49 | for (Map map : list) { 50 | // XViewBody child = new XViewBody(); 51 | XViewBody child = template.deepClone(); 52 | child.setComponentTemplate(child); 53 | child.setYiewStore(recyclerX.getYiewStore()); 54 | child.data = map; 55 | 56 | childs.add(child); 57 | } 58 | 59 | 60 | 61 | RecyclerAdapter adapter = new RecyclerAdapter(context,recyclerX, childs) { 62 | @Override 63 | protected void convert(AdapterHelper helper, XViewBody hotword, int position) { 64 | // helper.setText(R.id.item, hotword.keyword); 65 | 66 | 67 | } 68 | }; 69 | 70 | recyclerView.setAdapter(adapter); 71 | 72 | 73 | return recyclerView; 74 | 75 | } 76 | 77 | 78 | public void render(XViewBody yiew) { 79 | 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /XJsonViewLib/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Json2ViewLib 3 | 4 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.3' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /example_assets/how_it_works.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aarthas/android_Json2view/809039603ebae8b35c7fa45472c71244c20a18ce/example_assets/how_it_works.png -------------------------------------------------------------------------------- /example_assets/json2view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aarthas/android_Json2view/809039603ebae8b35c7fa45472c71244c20a18ce/example_assets/json2view.png -------------------------------------------------------------------------------- /example_assets/test00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aarthas/android_Json2view/809039603ebae8b35c7fa45472c71244c20a18ce/example_assets/test00.png -------------------------------------------------------------------------------- /example_assets/test01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aarthas/android_Json2view/809039603ebae8b35c7fa45472c71244c20a18ce/example_assets/test01.png -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aarthas/android_Json2view/809039603ebae8b35c7fa45472c71244c20a18ce/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Oct 06 01:23:45 PDT 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /javaCodeGenerate/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /javaCodeGenerate/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | 3 | dependencies { 4 | compile fileTree(include: ['*.jar'], dir: 'libs') 5 | compile 'com.google.code.gson:gson:2.7' 6 | compile files('libs/json-lib-2.4-jdk15.jar') 7 | compile files('libs/jackson-annotations-2.8.0.jar') 8 | compile files('libs/jackson-core-2.8.6.jar') 9 | compile files('libs/jackson-databind-2.8.6.jar') 10 | compile files('libs/jackson-datatype-jsr310-2.6.7.jar') 11 | } 12 | 13 | sourceCompatibility = "1.7" 14 | targetCompatibility = "1.7" 15 | -------------------------------------------------------------------------------- /javaCodeGenerate/complaintDetail.json: -------------------------------------------------------------------------------- 1 | { 2 | "view": "verticalLayout", 3 | "width": "match", 4 | "height": "match", 5 | "background": "#f6f6f6", 6 | "child": [ 7 | { 8 | "view": "refreshBar" 9 | }, 10 | { 11 | "view": "scrollView", 12 | "width": "match", 13 | "height": "match", 14 | "child": [ 15 | { 16 | "view": "verticalLayout", 17 | "width": "match", 18 | "height": "wrap", 19 | "background": "#f6f6f6", 20 | "gravity": "center", 21 | "child": [ 22 | { 23 | "view": "TextView", 24 | "text": "页面的简单使用", 25 | "textColor": "#444444", 26 | "padding": "16", 27 | "textSize": "16" 28 | 29 | 30 | }, 31 | { 32 | "view": "TextView", 33 | "text": "从assets/complaintDetail.json加载数据", 34 | "textColor": "#444444", 35 | "padding": "16", 36 | "gravity": "center", 37 | "textSize": "14", 38 | 39 | "click": "gotoDataSource" 40 | 41 | 42 | } 43 | ] 44 | }, 45 | { 46 | "name": "head1", 47 | "view": "RelativeLayout", 48 | "width": "match", 49 | "height": "48", 50 | "background": "#ffffff", 51 | "paddingLeft": "16", 52 | "paddingRight": "16", 53 | "child": [ 54 | { 55 | "view": "ImageView", 56 | "src": "http://onpxz5rdd.bkt.clouddn.com/ic_service_black.png", 57 | "width": "16dp", 58 | "height": "16dp", 59 | "layout_centerVertical": true 60 | }, 61 | { 62 | "view": "TextView", 63 | "text": "接受部门", 64 | "textColor": "#444444", 65 | "marginLeft": "24", 66 | "textSize": "14", 67 | "layout_centerVertical": true 68 | }, 69 | { 70 | "view": "TextView", 71 | "width": "wrap", 72 | "text": "状态", 73 | "textColor": "#444444", 74 | "layout_alignParentRight": "true", 75 | "layout_centerVertical": true 76 | } 77 | ] 78 | }, 79 | { 80 | "view": "line" 81 | }, 82 | { 83 | "name": "pane", 84 | "view": "RelativeLayout", 85 | "width": "match", 86 | "height": "wrap", 87 | "background": "#ffffff", 88 | "paddingLeft": "16", 89 | "paddingRight": "16", 90 | "paddingTop": "16", 91 | "paddingBottom": "16", 92 | "child": [ 93 | { 94 | "name": "platform", 95 | "view": "TextView", 96 | "text": "平台: wqrwer", 97 | "textColor": "#666666", 98 | "textSize": "14" 99 | }, 100 | { 101 | "name": "content1", 102 | "id": "102", 103 | "view": "TextView", 104 | "text": "内容: ", 105 | "textColor": "#666666", 106 | "marginTop": "12", 107 | "textSize": "14", 108 | "below": "@platform" 109 | }, 110 | { 111 | "view": "TextView", 112 | "text": "对于给您造成的不便我们深表抱歉。您的本次投诉已处理完成,如对处理结果不满意您可以再次投诉,谢谢!", 113 | "textColor": "#666666", 114 | "textSize": "14", 115 | "lineSpace": "18dp", 116 | "alignTop": "@content1", 117 | "toRightOf": "@content1" 118 | } 119 | ] 120 | }, 121 | { 122 | "name": "imagePane", 123 | "view": "horizonLayout", 124 | "width": "match_parent", 125 | "height": "wrap_content", 126 | "background": "#ffffff", 127 | "paddingLeft": "12dp", 128 | "paddingRight": "12dp", 129 | "paddingTop": "16", 130 | "paddingBottom": "10dp", 131 | "child": [ 132 | { 133 | "view": "ImageView", 134 | "src": "http://img.sanjiang.com/image/20173/1/image1488349927926.jpg", 135 | "width": "74dp", 136 | "height": "74dp", 137 | "margin": "5dp" 138 | }, 139 | { 140 | "view": "ImageView", 141 | "src": "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=232163874,2153671052&fm=58", 142 | "width": "74dp", 143 | "height": "74dp", 144 | "margin": "5dp" 145 | }, 146 | { 147 | "view": "ImageView", 148 | "src": "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=232163874,2153671052&fm=58", 149 | "width": "74dp", 150 | "height": "74dp", 151 | "margin": "5dp" 152 | }, 153 | { 154 | "view": "ImageView", 155 | "src": "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=232163874,2153671052&fm=58", 156 | "width": "74dp", 157 | "height": "74dp", 158 | "margin": "5dp" 159 | } 160 | ] 161 | }, 162 | { 163 | "name": "dv", 164 | "view": "View", 165 | "width": "match", 166 | "height": "16", 167 | "background": "#f6f6f6" 168 | }, 169 | { 170 | "name": "contact", 171 | "view": "RelativeLayout", 172 | "width": "match", 173 | "height": "48", 174 | "background": "#ffffff", 175 | "child": [ 176 | { 177 | "view": "TextView", 178 | "text": "联系人", 179 | "textColor": "#666666", 180 | "marginLeft": "24", 181 | "textSize": "14", 182 | "layout_centerVertical": true 183 | }, 184 | { 185 | "view": "TextView", 186 | "width": "wrap", 187 | "text": "my god", 188 | "textColor": "#666666", 189 | "layout_alignParentRight": true, 190 | "marginRight": "24", 191 | "layout_centerVertical": true 192 | } 193 | ] 194 | }, 195 | { 196 | "view": "line" 197 | }, 198 | { 199 | "name": "mobile", 200 | "view": "RelativeLayout", 201 | "width": "match", 202 | "height": "48", 203 | "background": "#ffffff", 204 | "child": [ 205 | { 206 | "view": "TextView", 207 | "text": "手机", 208 | "textColor": "#666666", 209 | "marginLeft": "24", 210 | "textSize": "14", 211 | "layout_centerVertical": true 212 | }, 213 | { 214 | "view": "TextView", 215 | "width": "wrap", 216 | "text": "132943...", 217 | "textColor": "#666666", 218 | "layout_alignParentRight": true, 219 | "marginRight": "24", 220 | "layout_centerVertical": true 221 | } 222 | ] 223 | }, 224 | { 225 | "view": "View", 226 | "width": "match", 227 | "height": "16", 228 | "background": "#f6f6f6" 229 | }, 230 | { 231 | "view": "verticalLayout", 232 | "width": "match", 233 | "height": "wrap", 234 | "padding": "20", 235 | "background": "#ffffff", 236 | "child": [ 237 | { 238 | "name": "attach1", 239 | "view": "TextView", 240 | "text": "对于给您造成的不便我们深表抱歉。您的本次投诉已处理完成,如对处理结果不满意您可以再次投诉,谢谢!", 241 | "textColor": "#666666", 242 | "lineSpace": "18dp", 243 | "textSize": "14" 244 | }, 245 | { 246 | "view": "View", 247 | "width": "match", 248 | "height": "36" 249 | }, 250 | { 251 | "view": "TextView", 252 | "text": "测试ScrollView\n测试ScrollView\n测试ScrollView\n测试ScrollView\n", 253 | "textColor": "#666666", 254 | "lineSpace": "18dp", 255 | "textSize": "14", 256 | "below": "@attach1" 257 | } 258 | ] 259 | } 260 | ] 261 | } 262 | ] 263 | } -------------------------------------------------------------------------------- /javaCodeGenerate/libs/jackson-annotations-2.8.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aarthas/android_Json2view/809039603ebae8b35c7fa45472c71244c20a18ce/javaCodeGenerate/libs/jackson-annotations-2.8.0.jar -------------------------------------------------------------------------------- /javaCodeGenerate/libs/jackson-core-2.8.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aarthas/android_Json2view/809039603ebae8b35c7fa45472c71244c20a18ce/javaCodeGenerate/libs/jackson-core-2.8.6.jar -------------------------------------------------------------------------------- /javaCodeGenerate/libs/jackson-databind-2.8.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aarthas/android_Json2view/809039603ebae8b35c7fa45472c71244c20a18ce/javaCodeGenerate/libs/jackson-databind-2.8.6.jar -------------------------------------------------------------------------------- /javaCodeGenerate/libs/jackson-datatype-jsr310-2.6.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aarthas/android_Json2view/809039603ebae8b35c7fa45472c71244c20a18ce/javaCodeGenerate/libs/jackson-datatype-jsr310-2.6.7.jar -------------------------------------------------------------------------------- /javaCodeGenerate/libs/json-lib-2.4-jdk15.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aarthas/android_Json2view/809039603ebae8b35c7fa45472c71244c20a18ce/javaCodeGenerate/libs/json-lib-2.4-jdk15.jar -------------------------------------------------------------------------------- /javaCodeGenerate/src/main/java/com/yi/UtilCopyMethod.java: -------------------------------------------------------------------------------- 1 | package com.yi; 2 | 3 | /** 4 | * Created by zhangyn on 17/4/12. 5 | */ 6 | 7 | public class UtilCopyMethod { 8 | public static void main(String[] args){ 9 | Integer a =1; 10 | System.out.println(a.toString()); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /javaCodeGenerate/src/main/java/com/yi/bean/ComponentBean.java: -------------------------------------------------------------------------------- 1 | package com.yi.bean; 2 | 3 | public class ComponentBean { 4 | 5 | public String name; 6 | public Yiew template; 7 | 8 | 9 | } -------------------------------------------------------------------------------- /javaCodeGenerate/src/main/java/com/yi/bean/HeadBean.java: -------------------------------------------------------------------------------- 1 | package com.yi.bean; 2 | 3 | import java.util.List; 4 | 5 | public class HeadBean { 6 | 7 | 8 | public String process; 9 | public List component; 10 | 11 | 12 | } -------------------------------------------------------------------------------- /javaCodeGenerate/src/main/java/com/yi/bean/PropertyBean.java: -------------------------------------------------------------------------------- 1 | package com.yi.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 | } -------------------------------------------------------------------------------- /javaCodeGenerate/src/main/java/com/yi/bean/Yiew.java: -------------------------------------------------------------------------------- 1 | package com.yi.bean; 2 | 3 | import java.util.ArrayList; 4 | 5 | /** 6 | * Created by zhangyn on 17/3/31. 7 | */ 8 | 9 | public class Yiew extends YiewBean { 10 | 11 | public static final String verticalLayout = "verticalLayout"; 12 | public static final String horizonLayout = "horizonLayout"; 13 | public static final String TextView = "TextView"; 14 | public static final String ImageView = "ImageView"; 15 | public static final String View = "View"; 16 | public static final String ScrollView = "ScrollView"; 17 | public static final String scrollView = "scrollView"; 18 | public static final String RelativeLayout = "RelativeLayout"; 19 | public static final String FrameLayout = "FrameLayout"; 20 | public static final String LinearLayout= "LinearLayout";; 21 | 22 | 23 | 24 | public static final String MATCH = "match"; 25 | public static final String WRAP = "wrap"; 26 | 27 | 28 | public transient Yiew parentNode; 29 | 30 | 31 | 32 | public void addChild(Yiew yiew) { 33 | if (child == null) 34 | { 35 | child = new ArrayList<>(); 36 | 37 | } 38 | child.add(yiew); 39 | } 40 | 41 | 42 | 43 | 44 | public static Yiew create(String type, String width, String height) { 45 | Yiew yiew = new Yiew(); 46 | yiew.view = type; 47 | yiew.width = width; 48 | yiew.height = height; 49 | return yiew; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /javaCodeGenerate/src/main/java/com/yi/bean/YiewBean.java: -------------------------------------------------------------------------------- 1 | package com.yi.bean; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | 6 | /** 7 | * Created by zhangyn on 17/3/29. 8 | */ 9 | 10 | 11 | public class YiewBean { 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 click; 21 | public String visibility; 22 | 23 | public String tag; 24 | 25 | 26 | public ArrayList propertys; 27 | public ArrayList child; 28 | public HashMap data; 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 | public int layout_toLeftOf; 78 | public int layout_toRightOf; 79 | public int layout_above; 80 | public int layout_below; 81 | 82 | public int layout_alignLeft; 83 | public int layout_alignRight; 84 | public int layout_alignTop; 85 | public int layout_alignBottom; 86 | 87 | 88 | 89 | 90 | 91 | public int layout_alignBaseline; 92 | 93 | 94 | //advance 95 | public String alignBaseline; 96 | public String below; 97 | public String alignBottom; 98 | public String toLeftOf; 99 | public String toRightOf; 100 | public String above; 101 | public String alignLeft; 102 | public String alignRight; 103 | public String alignTop; 104 | 105 | 106 | // @Override 107 | // public String toString() { 108 | // return "YiewBean{" + 109 | // "view='" + view + '\'' + 110 | // ", width='" + width + '\'' + 111 | // ", height='" + height + '\'' + 112 | // ", id=" + id + 113 | // ", click='" + click + '\'' + 114 | // ", visibility='" + visibility + '\'' + 115 | // ", tag='" + tag + '\'' + 116 | // ", propertys=" + propertys + 117 | // ", child=" + child + 118 | // ", padding=" + padding + 119 | // ", paddingLeft=" + paddingLeft + 120 | // ", paddingTop=" + paddingTop + 121 | // ", paddingRight=" + paddingRight + 122 | // ", paddingBottom=" + paddingBottom + 123 | // ", margin=" + margin + 124 | // ", marginLeft=" + marginLeft + 125 | // ", marginTop=" + marginTop + 126 | // ", marginRight=" + marginRight + 127 | // ", marginBottom=" + marginBottom + 128 | // ", background='" + background + '\'' + 129 | // ", gravity='" + gravity + '\'' + 130 | // ", layout_gravity='" + layout_gravity + '\'' + 131 | // ", weight=" + weight + 132 | // ", text='" + text + '\'' + 133 | // ", textSize=" + textSize + 134 | // ", textColor='" + textColor + '\'' + 135 | // ", hint='" + hint + '\'' + 136 | // ", maxLine=" + maxLine + 137 | // ", hintColor='" + hintColor + '\'' + 138 | // ", lineSpace=" + lineSpace + 139 | // ", scaleType='" + scaleType + '\'' + 140 | // ", src='" + src + '\'' + 141 | // ", layout_alignParentRight=" + layout_alignParentRight + 142 | // ", layout_alignParentLeft=" + layout_alignParentLeft + 143 | // ", layout_alignParentTop=" + layout_alignParentTop + 144 | // ", layout_alignParentBottom=" + layout_alignParentBottom + 145 | // ", layout_centerInParent=" + layout_centerInParent + 146 | // ", layout_centerHorizontal=" + layout_centerHorizontal + 147 | // ", layout_centerVertical=" + layout_centerVertical + 148 | // ", layout_toLeftOf=" + layout_toLeftOf + 149 | // ", layout_toRightOf=" + layout_toRightOf + 150 | // ", layout_above=" + layout_above + 151 | // ", layout_below=" + layout_below + 152 | // ", layout_alignLeft=" + layout_alignLeft + 153 | // ", layout_alignRight=" + layout_alignRight + 154 | // ", layout_alignTop=" + layout_alignTop + 155 | // ", layout_alignBottom=" + layout_alignBottom + 156 | // ", layout_alignBaseline=" + layout_alignBaseline + 157 | // '}'; 158 | // } 159 | } 160 | 161 | -------------------------------------------------------------------------------- /javaCodeGenerate/src/main/java/com/yi/bean/YiewResp.java: -------------------------------------------------------------------------------- 1 | package com.yi.bean; 2 | 3 | /** 4 | * Created by zhangyn on 17/4/7. 5 | */ 6 | 7 | public class YiewResp { 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","click":"showToast"},{"view":"group","background":"#f6f6f6","text":"普通事件"},{"name":"simpleEvent","click":"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 HeadBean head; 15 | public Yiew template; 16 | 17 | 18 | 19 | 20 | } 21 | -------------------------------------------------------------------------------- /javaCodeGenerate/src/main/java/com/yi/generate/ServerCodeGenerate.java: -------------------------------------------------------------------------------- 1 | package com.yi.generate; 2 | 3 | import com.yi.bean.Yiew; 4 | import com.yi.bean.YiewBean; 5 | 6 | 7 | import com.google.gson.Gson; 8 | 9 | import java.io.BufferedReader; 10 | import java.io.File; 11 | import java.io.FileInputStream; 12 | import java.io.InputStream; 13 | import java.io.InputStreamReader; 14 | import java.lang.reflect.Field; 15 | import java.util.ArrayList; 16 | 17 | public class ServerCodeGenerate { 18 | 19 | 20 | public static void main(String[] args) throws Exception, IllegalAccessException { 21 | 22 | 23 | File file = new File("javaCodeGenerate/complaintDetail.json"); 24 | // file.createNewFile(); 25 | 26 | String s = readFile(file); 27 | System.out.println(s); 28 | Gson gson = new Gson(); 29 | 30 | Yiew yiewBean = gson.fromJson(s, Yiew.class); 31 | // YiewEngine.createmyiew(yiewBean) 32 | 33 | 34 | create(null, "yiew_1", yiewBean); 35 | 36 | // int count = 0; 37 | // if (yiewBean!= null) 38 | // { 39 | // String yiewName = "yiew"; 40 | // System.out.println(" Yiew "+yiewName+" = new Yiew();"); 41 | // Field[] declaredFields = YiewBean.class.getDeclaredFields(); 42 | // for (Field declaredField : declaredFields) { 43 | // 44 | // } 45 | // 46 | // yiew.view = "verticalLayout"; 47 | // 48 | // } 49 | 50 | 51 | } 52 | 53 | private static void create(String parentName, String yiewName, YiewBean yiewBean) throws IllegalAccessException { 54 | 55 | 56 | System.out.println(" Yiew " + yiewName + " = new Yiew();"); 57 | if (parentName != null) { 58 | System.out.println(" " + parentName + ".addChild(" + yiewName + ");"); 59 | } 60 | 61 | Field[] declaredFields = YiewBean.class.getDeclaredFields(); 62 | for (Field declaredField : declaredFields) { 63 | String name = declaredField.getName(); 64 | if (declaredField.getType() == String.class) { 65 | 66 | String value = (String) declaredField.get(yiewBean); 67 | if (value != null) { 68 | System.out.println("" + yiewName + "." + name + " = \"" + value + "\";"); 69 | } 70 | 71 | 72 | } 73 | if (declaredField.getType() == int.class) { 74 | 75 | 76 | int value = Integer.parseInt(declaredField.get(yiewBean).toString()); 77 | if (value != 0) { 78 | System.out.println("" + yiewName + "." + name + " = " + value + ";"); 79 | } 80 | 81 | } 82 | if (declaredField.getType() == boolean.class) { 83 | 84 | // System.out.println(name); 85 | // System.out.println(declaredField.get(yiewBean).toString()); 86 | boolean value = Boolean.valueOf(declaredField.get(yiewBean).toString()); 87 | if (value) { 88 | System.out.println("" + yiewName + "." + name + " = " + value + ";"); 89 | } 90 | } 91 | 92 | 93 | } 94 | 95 | ArrayList child = yiewBean.child; 96 | // System.out.println(child); 97 | if (child != null) { 98 | for (int i = 0; i < child.size(); i++) { 99 | 100 | YiewBean yiewBean1 = child.get(i); 101 | 102 | 103 | System.out.println("\n"); 104 | String childName = yiewName + "_" + (i + 1); 105 | create(yiewName, childName, yiewBean1); 106 | 107 | 108 | } 109 | 110 | 111 | } 112 | } 113 | 114 | 115 | private static String readFile(File fileName) { 116 | StringBuilder returnString = new StringBuilder(); 117 | InputStream fileInputStream = null; 118 | InputStreamReader isr = null; 119 | BufferedReader input = null; 120 | try { 121 | fileInputStream = new FileInputStream(fileName); 122 | 123 | isr = new InputStreamReader(fileInputStream); 124 | input = new BufferedReader(isr); 125 | String line; 126 | while ((line = input.readLine()) != null) { 127 | returnString.append(line); 128 | } 129 | } catch (Exception e) { 130 | e.getMessage(); 131 | } finally { 132 | try { 133 | if (isr != null) 134 | isr.close(); 135 | if (fileInputStream != null) 136 | fileInputStream.close(); 137 | if (input != null) 138 | input.close(); 139 | 140 | } catch (Exception e2) { 141 | e2.getMessage(); 142 | } 143 | } 144 | return returnString.toString(); 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /javaCodeGenerate/src/main/java/com/yi/generate/ServerCodeGenerateTest.java: -------------------------------------------------------------------------------- 1 | package com.yi.generate; 2 | 3 | public class ServerCodeGenerateTest { 4 | 5 | 6 | public static void main(String[] args) throws Exception, IllegalAccessException { 7 | 8 | // Yiew yiew_1 = new Yiew(); 9 | // yiew_1.view = "scrollView"; 10 | // yiew_1.width = "match"; 11 | // yiew_1.height = "match"; 12 | // yiew_1.background = "#f6f6f6"; 13 | // 14 | // 15 | // Yiew yiew_1_1 = new Yiew(); 16 | // yiew_1.addChild(yiew_1_1); 17 | // yiew_1_1.view = "refreshBar"; 18 | // 19 | // 20 | // Yiew yiew_1_2 = new Yiew(); 21 | // yiew_1.addChild(yiew_1_2); 22 | // yiew_1_2.name = "dv"; 23 | // yiew_1_2.view = "View"; 24 | // yiew_1_2.width = "match"; 25 | // yiew_1_2.height = "16"; 26 | // yiew_1_2.background = "#f6f6f6"; 27 | // 28 | // 29 | // Yiew yiew_1_3 = new Yiew(); 30 | // yiew_1.addChild(yiew_1_3); 31 | // yiew_1_3.name = "head1"; 32 | // yiew_1_3.view = "RelativeLayout"; 33 | // yiew_1_3.width = "match"; 34 | // yiew_1_3.height = "48"; 35 | // yiew_1_3.paddingLeft = "16"; 36 | // yiew_1_3.paddingRight = "16"; 37 | // yiew_1_3.background = "#ffffff"; 38 | // 39 | // 40 | // Yiew yiew_1_3_1 = new Yiew(); 41 | // yiew_1_3.addChild(yiew_1_3_1); 42 | // yiew_1_3_1.view = "ImageView"; 43 | // yiew_1_3_1.width = "16dp"; 44 | // yiew_1_3_1.height = "16dp"; 45 | // yiew_1_3_1.src = "http://onpxz5rdd.bkt.clouddn.com/ic_service_black.png"; 46 | // yiew_1_3_1.layout_centerVertical = true; 47 | // 48 | // 49 | // Yiew yiew_1_3_2 = new Yiew(); 50 | // yiew_1_3.addChild(yiew_1_3_2); 51 | // yiew_1_3_2.view = "TextView"; 52 | // yiew_1_3_2.marginLeft = "24"; 53 | // yiew_1_3_2.text = "舒服舒服"; 54 | // yiew_1_3_2.textSize = 14; 55 | // yiew_1_3_2.textColor = "#444444"; 56 | // yiew_1_3_2.layout_centerVertical = true; 57 | // 58 | // 59 | // Yiew yiew_1_3_3 = new Yiew(); 60 | // yiew_1_3.addChild(yiew_1_3_3); 61 | // yiew_1_3_3.view = "TextView"; 62 | // yiew_1_3_3.width = "wrap"; 63 | // yiew_1_3_3.text = "close"; 64 | // yiew_1_3_3.textColor = "#444444"; 65 | // yiew_1_3_3.layout_alignParentRight = true; 66 | // yiew_1_3_3.layout_centerVertical = true; 67 | // 68 | // 69 | // Yiew yiew_1_4 = new Yiew(); 70 | // yiew_1.addChild(yiew_1_4); 71 | // yiew_1_4.view = "line"; 72 | // 73 | // 74 | // Yiew yiew_1_5 = new Yiew(); 75 | // yiew_1.addChild(yiew_1_5); 76 | // yiew_1_5.name = "pane"; 77 | // yiew_1_5.view = "RelativeLayout"; 78 | // yiew_1_5.width = "match"; 79 | // yiew_1_5.height = "wrap"; 80 | // yiew_1_5.paddingLeft = "16"; 81 | // yiew_1_5.paddingTop = "16"; 82 | // yiew_1_5.paddingRight = "16"; 83 | // yiew_1_5.paddingBottom = "16"; 84 | // yiew_1_5.background = "#ffffff"; 85 | // 86 | // 87 | // Yiew yiew_1_5_1 = new Yiew(); 88 | // yiew_1_5.addChild(yiew_1_5_1); 89 | // yiew_1_5_1.name = "platform"; 90 | // yiew_1_5_1.view = "TextView"; 91 | // yiew_1_5_1.text = "购买平台: wqrwer"; 92 | // yiew_1_5_1.textSize = 14; 93 | // yiew_1_5_1.textColor = "#666666"; 94 | // 95 | // 96 | // Yiew yiew_1_5_2 = new Yiew(); 97 | // yiew_1_5.addChild(yiew_1_5_2); 98 | // yiew_1_5_2.name = "content1"; 99 | // yiew_1_5_2.view = "TextView"; 100 | // yiew_1_5_2.id = 102; 101 | // yiew_1_5_2.marginTop = "12"; 102 | // yiew_1_5_2.text = "阿萨德啊: "; 103 | // yiew_1_5_2.textSize = 14; 104 | // yiew_1_5_2.textColor = "#666666"; 105 | // yiew_1_5_2.below = "@platform"; 106 | // 107 | // 108 | // Yiew yiew_1_5_3 = new Yiew(); 109 | // yiew_1_5.addChild(yiew_1_5_3); 110 | // yiew_1_5_3.view = "TextView"; 111 | // yiew_1_5_3.text = "订单号订单号订单号订单号订单号订单号订单号"; 112 | // yiew_1_5_3.textSize = 14; 113 | // yiew_1_5_3.textColor = "#666666"; 114 | // yiew_1_5_3.toRightOf = "@content1"; 115 | // yiew_1_5_3.alignTop = "@content1"; 116 | // 117 | // 118 | // Yiew yiew_1_6 = new Yiew(); 119 | // yiew_1.addChild(yiew_1_6); 120 | // yiew_1_6.name = "imagePane"; 121 | // yiew_1_6.view = "horizonLayout"; 122 | // yiew_1_6.width = "match_parent"; 123 | // yiew_1_6.height = "wrap_content"; 124 | // yiew_1_6.paddingLeft = "12dp"; 125 | // yiew_1_6.paddingTop = "16"; 126 | // yiew_1_6.paddingRight = "12dp"; 127 | // yiew_1_6.paddingBottom = "10dp"; 128 | // yiew_1_6.background = "#ffffff"; 129 | // 130 | // 131 | // Yiew yiew_1_6_1 = new Yiew(); 132 | // yiew_1_6.addChild(yiew_1_6_1); 133 | // yiew_1_6_1.view = "ImageView"; 134 | // yiew_1_6_1.width = "74dp"; 135 | // yiew_1_6_1.height = "74dp"; 136 | // yiew_1_6_1.margin = "5dp"; 137 | // yiew_1_6_1.src = "http://img.sanjiang.com/image/20173/1/image1488349927926.jpg"; 138 | // 139 | // 140 | // Yiew yiew_1_6_2 = new Yiew(); 141 | // yiew_1_6.addChild(yiew_1_6_2); 142 | // yiew_1_6_2.view = "ImageView"; 143 | // yiew_1_6_2.width = "74dp"; 144 | // yiew_1_6_2.height = "74dp"; 145 | // yiew_1_6_2.margin = "5dp"; 146 | // yiew_1_6_2.src = "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=232163874,2153671052&fm=58"; 147 | // 148 | // 149 | // Yiew yiew_1_6_3 = new Yiew(); 150 | // yiew_1_6.addChild(yiew_1_6_3); 151 | // yiew_1_6_3.view = "ImageView"; 152 | // yiew_1_6_3.width = "74dp"; 153 | // yiew_1_6_3.height = "74dp"; 154 | // yiew_1_6_3.margin = "5dp"; 155 | // yiew_1_6_3.src = "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=232163874,2153671052&fm=58"; 156 | // 157 | // 158 | // Yiew yiew_1_6_4 = new Yiew(); 159 | // yiew_1_6.addChild(yiew_1_6_4); 160 | // yiew_1_6_4.view = "ImageView"; 161 | // yiew_1_6_4.width = "74dp"; 162 | // yiew_1_6_4.height = "74dp"; 163 | // yiew_1_6_4.margin = "5dp"; 164 | // yiew_1_6_4.src = "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=232163874,2153671052&fm=58"; 165 | // 166 | // 167 | // Yiew yiew_1_7 = new Yiew(); 168 | // yiew_1.addChild(yiew_1_7); 169 | // yiew_1_7.name = "dv"; 170 | // yiew_1_7.view = "View"; 171 | // yiew_1_7.width = "match"; 172 | // yiew_1_7.height = "16"; 173 | // yiew_1_7.background = "#f6f6f6"; 174 | // 175 | // 176 | // Yiew yiew_1_8 = new Yiew(); 177 | // yiew_1.addChild(yiew_1_8); 178 | // yiew_1_8.name = "contact"; 179 | // yiew_1_8.view = "RelativeLayout"; 180 | // yiew_1_8.width = "match"; 181 | // yiew_1_8.height = "48"; 182 | // yiew_1_8.background = "#ffffff"; 183 | // 184 | // 185 | // Yiew yiew_1_8_1 = new Yiew(); 186 | // yiew_1_8.addChild(yiew_1_8_1); 187 | // yiew_1_8_1.view = "TextView"; 188 | // yiew_1_8_1.marginLeft = "24"; 189 | // yiew_1_8_1.text = "舒服舒服"; 190 | // yiew_1_8_1.textSize = 14; 191 | // yiew_1_8_1.textColor = "#666666"; 192 | // yiew_1_8_1.layout_centerVertical = true; 193 | // 194 | // 195 | // Yiew yiew_1_8_2 = new Yiew(); 196 | // yiew_1_8.addChild(yiew_1_8_2); 197 | // yiew_1_8_2.view = "TextView"; 198 | // yiew_1_8_2.width = "wrap"; 199 | // yiew_1_8_2.marginRight = "24"; 200 | // yiew_1_8_2.text = "aa"; 201 | // yiew_1_8_2.textColor = "#666666"; 202 | // yiew_1_8_2.layout_alignParentRight = true; 203 | // yiew_1_8_2.layout_centerVertical = true; 204 | // 205 | // 206 | // Yiew yiew_1_9 = new Yiew(); 207 | // yiew_1.addChild(yiew_1_9); 208 | // yiew_1_9.view = "line"; 209 | // 210 | // 211 | // Yiew yiew_1_10 = new Yiew(); 212 | // yiew_1.addChild(yiew_1_10); 213 | // yiew_1_10.name = "mobile"; 214 | // yiew_1_10.view = "RelativeLayout"; 215 | // yiew_1_10.width = "match"; 216 | // yiew_1_10.height = "48"; 217 | // yiew_1_10.background = "#ffffff"; 218 | // 219 | // 220 | // Yiew yiew_1_10_1 = new Yiew(); 221 | // yiew_1_10.addChild(yiew_1_10_1); 222 | // yiew_1_10_1.view = "TextView"; 223 | // yiew_1_10_1.marginLeft = "24"; 224 | // yiew_1_10_1.text = "舒服舒服"; 225 | // yiew_1_10_1.textSize = 14; 226 | // yiew_1_10_1.textColor = "#666666"; 227 | // yiew_1_10_1.layout_centerVertical = true; 228 | // 229 | // 230 | // Yiew yiew_1_10_2 = new Yiew(); 231 | // yiew_1_10.addChild(yiew_1_10_2); 232 | // yiew_1_10_2.view = "TextView"; 233 | // yiew_1_10_2.width = "wrap"; 234 | // yiew_1_10_2.marginRight = "24"; 235 | // yiew_1_10_2.text = ""; 236 | // yiew_1_10_2.textColor = "#666666"; 237 | // yiew_1_10_2.layout_alignParentRight = true; 238 | // yiew_1_10_2.layout_centerVertical = true; 239 | // 240 | // 241 | // Yiew yiew_1_11 = new Yiew(); 242 | // yiew_1.addChild(yiew_1_11); 243 | // yiew_1_11.name = "attach"; 244 | // yiew_1_11.view = "View"; 245 | // yiew_1_11.width = "match"; 246 | // yiew_1_11.height = "16"; 247 | // yiew_1_11.background = "#f6f6f6"; 248 | // 249 | // 250 | // Yiew yiew_1_12 = new Yiew(); 251 | // yiew_1.addChild(yiew_1_12); 252 | // yiew_1_12.view = "RelativeLayout"; 253 | // yiew_1_12.width = "match"; 254 | // yiew_1_12.height = "wrap"; 255 | // yiew_1_12.padding = "20"; 256 | // yiew_1_12.background = "#ffffff"; 257 | // 258 | // 259 | // Yiew yiew_1_12_1 = new Yiew(); 260 | // yiew_1_12.addChild(yiew_1_12_1); 261 | // yiew_1_12_1.view = "TextView"; 262 | // yiew_1_12_1.text = "对于给您造成的不便我们深表抱歉。您的本次投诉已处理完成,如对处理结果不满意您可以再次投诉,谢谢!"; 263 | // yiew_1_12_1.textSize = 14; 264 | // yiew_1_12_1.textColor = "#666666"; 265 | // yiew_1_12_1.lineSpace = "8"; 266 | // yiew_1_12_1.layout_centerVertical = true; 267 | 268 | 269 | } 270 | 271 | 272 | } 273 | -------------------------------------------------------------------------------- /javaCodeGenerate/src/main/java/com/yi/generate/UtilCopyMethod.java: -------------------------------------------------------------------------------- 1 | package com.yi.generate; 2 | 3 | 4 | import com.yi.bean.YiewBean; 5 | 6 | import java.lang.reflect.Field; 7 | import java.util.ArrayList; 8 | 9 | public class UtilCopyMethod { 10 | 11 | 12 | public static void main(String[] args) throws Exception, IllegalAccessException { 13 | 14 | Field[] declaredFields = YiewBean.class.getDeclaredFields(); 15 | for (Field declaredField : declaredFields) { 16 | String name = declaredField.getName(); 17 | if (declaredField.getType() == String.class) { 18 | System.out.println(" if (from."+name+" != null) {"); 19 | System.out.println(" to."+name+"=from."+name+";"); 20 | System.out.println(" }"); 21 | 22 | } 23 | if (declaredField.getType() == int.class) { 24 | 25 | 26 | System.out.println(" if (from."+name+" != 0) {"); 27 | System.out.println(" to."+name+"=from."+name+";"); 28 | System.out.println(" }"); 29 | } 30 | if (declaredField.getType() == boolean.class) { 31 | 32 | 33 | System.out.println(" if (from."+name+") {"); 34 | System.out.println(" to."+name+"=from."+name+";"); 35 | System.out.println("}"); 36 | 37 | } 38 | if (declaredField.getType() == ArrayList.class) { 39 | 40 | 41 | // System.out.println(" if (yiew."+name+" != null ) {"); 42 | // System.out.println(" yiew1."+name+"=yiew."+name+";"); 43 | // System.out.println("}"); 44 | } 45 | 46 | } 47 | 48 | 49 | 50 | 51 | 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /javaCodeGenerate/src/main/java/com/yi/generate/UtilCopyMethod2.java: -------------------------------------------------------------------------------- 1 | package com.yi.generate; 2 | 3 | 4 | import com.yi.bean.YiewBean; 5 | 6 | import java.lang.reflect.Field; 7 | import java.util.ArrayList; 8 | 9 | public class UtilCopyMethod2 { 10 | 11 | 12 | public static void main(String[] args) throws Exception, IllegalAccessException { 13 | 14 | Field[] declaredFields = YiewBean.class.getDeclaredFields(); 15 | for (Field declaredField : declaredFields) { 16 | String name = declaredField.getName(); 17 | if (declaredField.getType() == String.class) { 18 | System.out.println(" if (to."+name+" == null) {"); 19 | System.out.println(" to."+name+"=from."+name+";"); 20 | System.out.println(" }"); 21 | 22 | } 23 | if (declaredField.getType() == int.class) { 24 | 25 | 26 | System.out.println(" if (to."+name+" == 0) {"); 27 | System.out.println(" to."+name+"=from."+name+";"); 28 | System.out.println(" }"); 29 | } 30 | if (declaredField.getType() == boolean.class) { 31 | 32 | 33 | System.out.println(" if (!to."+name+") {"); 34 | System.out.println(" to."+name+"=from."+name+";"); 35 | System.out.println("}"); 36 | 37 | } 38 | if (declaredField.getType() == ArrayList.class) { 39 | 40 | 41 | // System.out.println(" if (yiew."+name+" != null ) {"); 42 | // System.out.println(" yiew1."+name+"=yiew."+name+";"); 43 | // System.out.println("}"); 44 | } 45 | 46 | } 47 | 48 | 49 | 50 | 51 | 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /javaCodeGenerate/src/main/java/com/yi/generate/YiewSerializeGererate.java: -------------------------------------------------------------------------------- 1 | package com.yi.generate; 2 | 3 | 4 | import com.yi.bean.YiewBean; 5 | 6 | import java.lang.reflect.Field; 7 | import java.util.ArrayList; 8 | 9 | public class YiewSerializeGererate { 10 | 11 | 12 | public static void main(String[] args) throws Exception, IllegalAccessException { 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | Field[] declaredFields = YiewBean.class.getDeclaredFields(); 22 | for (Field declaredField : declaredFields) { 23 | String name = declaredField.getName(); 24 | if (declaredField.getType() == String.class) { 25 | 26 | // String value = (String) declaredField.get(obj); 27 | // if (value!=null) 28 | // { 29 | // 30 | // } 31 | System.out.println(" if (obj."+name+" != null) {"); 32 | System.out.println(" hashMap.put(\""+name+"\", obj."+name+");"); 33 | System.out.println("}"); 34 | 35 | } 36 | if (declaredField.getType() == int.class) { 37 | 38 | 39 | System.out.println(" if (obj."+name+" != 0) {"); 40 | System.out.println(" hashMap.put(\""+name+"\", obj."+name+");"); 41 | System.out.println("}"); 42 | 43 | } 44 | if (declaredField.getType() == boolean.class) { 45 | 46 | 47 | System.out.println(" if (obj."+name+") {"); 48 | System.out.println(" hashMap.put(\""+name+"\", obj."+name+");"); 49 | System.out.println("}"); 50 | 51 | } 52 | if (declaredField.getType() == ArrayList.class) { 53 | 54 | 55 | System.out.println(" if (obj."+name+" != null ) {"); 56 | System.out.println(" hashMap.put(\""+name+"\", obj."+name+");"); 57 | System.out.println("}"); 58 | 59 | } 60 | 61 | } 62 | 63 | 64 | 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /javaCodeGenerate/textview.json: -------------------------------------------------------------------------------- 1 | { 2 | "view": "verticalLayout", 3 | "width": "match", 4 | "height": "match", 5 | "background": "#f6f6f6", 6 | "weight": 1, 7 | 8 | "child": [ 9 | { 10 | "view": "RelativeLayout", 11 | "width": "match", 12 | "height": "48", 13 | "background": "#ffffff", 14 | "property": { 15 | }, 16 | "child": [ 17 | { 18 | "id": 1001, 19 | "view": "TextView", 20 | "width": "wrap", 21 | "text": "客户投诉", 22 | "textColor": "#999999", 23 | "height": "wrap", 24 | "layout_centerInParent": true 25 | }, 26 | { 27 | "id": 1002, 28 | "view": "TextView", 29 | "width": "100", 30 | "height": "48", 31 | "text": "刷续", 32 | "textColor": "#666666", 33 | 34 | "gravity":"center", 35 | 36 | "click": "refresh", 37 | "background": "#999999", 38 | "layout_alignParentRight":true 39 | } 40 | 41 | 42 | ] 43 | }, 44 | 45 | { 46 | "view": "TextView", 47 | "width": "match", 48 | "height": "48", 49 | "gravity": "CENTER", 50 | "text": "aa", 51 | "textSize": 18, 52 | 53 | "textColor": "#999999", 54 | 55 | "property": { 56 | }, 57 | "child": [ 58 | ] 59 | }, 60 | { 61 | "view": "View", 62 | "width": "match", 63 | "unit": "px", 64 | "height": "1", 65 | "background": "#e1e1e1" 66 | }, 67 | { 68 | "view": "horizonLayout", 69 | "width": "match", 70 | "height": "wrap", 71 | "child": [ 72 | { 73 | "id": 1001, 74 | "view": "TextView", 75 | "width": "wrap", 76 | "text": "bb", 77 | "textColor": "#333333", 78 | "height": "wrap", 79 | "margin": "20", 80 | "click": "myClick", 81 | "background": "#cccccc", 82 | "padding": "20" 83 | }, 84 | { 85 | "id": 1002, 86 | "view": "TextView", 87 | "width": "wrap", 88 | "text": "cc", 89 | "textColor": "#666666", 90 | "height": "wrap", 91 | "margin": "20", 92 | "click": "myClick2", 93 | "background": "#eeeeee", 94 | "padding": "20" 95 | } 96 | ] 97 | } 98 | ] 99 | } -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "24.0.2" 6 | 7 | defaultConfig { 8 | applicationId "com.avocarrot.json2view" 9 | minSdkVersion 15 10 | targetSdkVersion 24 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | 15 | lintOptions { 16 | abortOnError false 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | } 26 | 27 | dependencies { 28 | compile fileTree(dir: 'libs', include: ['*.jar']) 29 | compile 'com.android.support:appcompat-v7:24.2.1' 30 | compile 'com.android.support:support-v4:24.2.1' 31 | // compile project(':json2view') 32 | compile 'com.google.code.gson:gson:2.7' 33 | compile 'com.github.bumptech.glide:glide:3.7.0' 34 | compile 'com.lzy.net:okgo:2.1.4' 35 | // compile project(':yiewlib') 36 | compile project(path: ':XJsonViewLib') 37 | compile 'com.lzy.net:okgo:2.1.4' 38 | compile 'com.google.android:flexbox:0.2.6' 39 | // compile project(path: ':yiewlib') 40 | compile 'com.apkfuns.logutils:library:1.5.1.1' 41 | 42 | 43 | 44 | compile 'com.android.support:recyclerview-v7:24.2.1' 45 | 46 | compile 'com.alibaba:fastjson:1.1.46.android' 47 | compile 'com.taobao.android:weex_sdk:0.5.1@aar' 48 | } 49 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 17 | 18 | 19 | 20 | 21 | 25 | 26 | 27 | 28 | 29 | 33 | 34 | 35 | 39 | 40 | 44 | 45 | 49 | 50 | 54 | 55 | 56 | 60 | 61 | 62 | 66 | 67 | 68 | 69 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /sample/src/main/assets/complaintDetail.json: -------------------------------------------------------------------------------- 1 | { 2 | "head": { 3 | "process": "AndroidLayout" 4 | }, 5 | "template": { 6 | "view": "verticalLayout", 7 | "width": "match", 8 | "height": "match", 9 | "background": "#f6f6f6", 10 | "child": [ 11 | { 12 | "view": "refreshBar" 13 | }, 14 | { 15 | "view": "scrollView", 16 | "width": "match", 17 | "height": "match", 18 | "child": [ 19 | { 20 | "view": "verticalLayout", 21 | "width": "match", 22 | "height": "wrap", 23 | "background": "#f6f6f6", 24 | "gravity": "center", 25 | "child": [ 26 | { 27 | "view": "TextView", 28 | "text": "页面的简单使用", 29 | "textColor": "#444444", 30 | "padding": "16", 31 | "textSize": "16" 32 | }, 33 | { 34 | "view": "TextView", 35 | "text": "从assets/complaintDetail.json加载数据", 36 | "textColor": "#444444", 37 | "padding": "16", 38 | "gravity": "center", 39 | "textSize": "14", 40 | "onClick": "gotoDataSource" 41 | } 42 | ] 43 | }, 44 | { 45 | "name": "head1", 46 | "view": "RelativeLayout", 47 | "width": "match", 48 | "height": "48", 49 | "background": "#ffffff", 50 | "paddingLeft": "16", 51 | "paddingRight": "16", 52 | "child": [ 53 | { 54 | "view": "ImageView", 55 | "src": "http://onpxz5rdd.bkt.clouddn.com/ic_service_black.png", 56 | "width": "16dp", 57 | "height": "16dp", 58 | "layout_centerVertical": true 59 | }, 60 | { 61 | "view": "TextView", 62 | "text": "接受部门", 63 | "textColor": "#444444", 64 | "marginLeft": "24", 65 | "textSize": "14", 66 | "layout_centerVertical": true 67 | }, 68 | { 69 | "view": "TextView", 70 | "width": "wrap", 71 | "text": "状态", 72 | "textColor": "#444444", 73 | "layout_alignParentRight": "true", 74 | "layout_centerVertical": true 75 | } 76 | ] 77 | }, 78 | { 79 | "view": "line" 80 | }, 81 | { 82 | "name": "pane", 83 | "view": "RelativeLayout", 84 | "width": "match", 85 | "height": "wrap", 86 | "background": "#ffffff", 87 | "paddingLeft": "16", 88 | "paddingRight": "16", 89 | "paddingTop": "16", 90 | "paddingBottom": "16", 91 | "child": [ 92 | { 93 | "name": "platform", 94 | "view": "TextView", 95 | "text": "平台: wqrwer", 96 | "textColor": "#666666", 97 | "textSize": "14" 98 | }, 99 | { 100 | "name": "content1", 101 | "id": "102", 102 | "view": "TextView", 103 | "text": "内容: ", 104 | "textColor": "#666666", 105 | "marginTop": "12", 106 | "textSize": "14", 107 | "below": "@platform" 108 | }, 109 | { 110 | "view": "TextView", 111 | "text": "对于给您造成的不便我们深表抱歉。您的本次投诉已处理完成,如对处理结果不满意您可以再次投诉,谢谢!", 112 | "textColor": "#666666", 113 | "textSize": "14", 114 | "lineSpace": "18dp", 115 | "alignTop": "@content1", 116 | "toRightOf": "@content1" 117 | } 118 | ] 119 | }, 120 | { 121 | "name": "imagePane", 122 | "view": "horizonLayout", 123 | "width": "match_parent", 124 | "height": "wrap_content", 125 | "background": "#ffffff", 126 | "paddingLeft": "12dp", 127 | "paddingRight": "12dp", 128 | "paddingTop": "16", 129 | "paddingBottom": "10dp", 130 | "child": [ 131 | { 132 | "view": "ImageView", 133 | "src": "http://img.sanjiang.com/image/20173/1/image1488349927926.jpg", 134 | "width": "74dp", 135 | "height": "74dp", 136 | "margin": "5dp" 137 | }, 138 | { 139 | "view": "ImageView", 140 | "src": "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=232163874,2153671052&fm=58", 141 | "width": "74dp", 142 | "height": "74dp", 143 | "margin": "5dp" 144 | }, 145 | { 146 | "view": "ImageView", 147 | "src": "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=232163874,2153671052&fm=58", 148 | "width": "74dp", 149 | "height": "74dp", 150 | "margin": "5dp" 151 | }, 152 | { 153 | "view": "ImageView", 154 | "src": "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=232163874,2153671052&fm=58", 155 | "width": "74dp", 156 | "height": "74dp", 157 | "margin": "5dp" 158 | } 159 | ] 160 | }, 161 | { 162 | "name": "dv", 163 | "view": "View", 164 | "width": "match", 165 | "height": "16", 166 | "background": "#f6f6f6" 167 | }, 168 | { 169 | "name": "contact", 170 | "view": "RelativeLayout", 171 | "width": "match", 172 | "height": "48", 173 | "background": "#ffffff", 174 | "child": [ 175 | { 176 | "view": "TextView", 177 | "text": "联系人", 178 | "textColor": "#666666", 179 | "marginLeft": "24", 180 | "textSize": "14", 181 | "layout_centerVertical": true 182 | }, 183 | { 184 | "view": "TextView", 185 | "width": "wrap", 186 | "text": "my god", 187 | "textColor": "#666666", 188 | "layout_alignParentRight": true, 189 | "marginRight": "24", 190 | "layout_centerVertical": true 191 | } 192 | ] 193 | }, 194 | { 195 | "view": "line" 196 | }, 197 | { 198 | "name": "mobile", 199 | "view": "RelativeLayout", 200 | "width": "match", 201 | "height": "48", 202 | "background": "#ffffff", 203 | "child": [ 204 | { 205 | "view": "TextView", 206 | "text": "手机", 207 | "textColor": "#666666", 208 | "marginLeft": "24", 209 | "textSize": "14", 210 | "layout_centerVertical": true 211 | }, 212 | { 213 | "view": "TextView", 214 | "width": "wrap", 215 | "text": "132943...", 216 | "textColor": "#666666", 217 | "layout_alignParentRight": true, 218 | "marginRight": "24", 219 | "layout_centerVertical": true 220 | } 221 | ] 222 | }, 223 | { 224 | "view": "View", 225 | "width": "match", 226 | "height": "16", 227 | "background": "#f6f6f6" 228 | }, 229 | { 230 | "view": "verticalLayout", 231 | "width": "match", 232 | "height": "wrap", 233 | "padding": "20", 234 | "background": "#ffffff", 235 | "child": [ 236 | { 237 | "name": "attach1", 238 | "view": "TextView", 239 | "text": "对于给您造成的不便我们深表抱歉。您的本次投诉已处理完成,如对处理结果不满意您可以再次投诉,谢谢!", 240 | "textColor": "#666666", 241 | "lineSpace": "18dp", 242 | "textSize": "14" 243 | }, 244 | { 245 | "view": "View", 246 | "width": "match", 247 | "height": "36" 248 | }, 249 | { 250 | "view": "TextView", 251 | "text": "测试ScrollView\n测试ScrollView\n测试ScrollView\n测试ScrollView\n", 252 | "textColor": "#666666", 253 | "lineSpace": "18dp", 254 | "textSize": "14", 255 | "below": "@attach1" 256 | } 257 | ] 258 | } 259 | ] 260 | } 261 | ] 262 | } 263 | } -------------------------------------------------------------------------------- /sample/src/main/assets/feature.json: -------------------------------------------------------------------------------- 1 | { 2 | "head": { 3 | "process": "AndroidLayout" 4 | 5 | }, 6 | "template": { 7 | "view": "verticalLayout", 8 | "width": "match", 9 | "height": "match", 10 | "background": "#f6f6f6", 11 | "child": [ 12 | { 13 | "view": "refreshBar" 14 | }, 15 | { 16 | "view": "scrollView", 17 | "width": "match", 18 | "height": "match", 19 | "child": [ 20 | { 21 | "view": "localComponent2", 22 | "data": { 23 | "text": "本地组件" 24 | } 25 | }, 26 | { 27 | "view": "localComponent" 28 | }, 29 | { 30 | "view": "localComponent", 31 | "background": "#fb9236", 32 | "data": { 33 | "text": "background覆盖父控件,text覆盖子控件", 34 | "textColor": "#fff" 35 | } 36 | }, 37 | 38 | { 39 | "view": "localComponent2", 40 | "data": { 41 | "text": "事件" 42 | } 43 | }, 44 | { 45 | "view": "localComponent", 46 | "background": "#56b0f5", 47 | "data": { 48 | "text": "component事件,点击调用activity的showToast方法" 49 | }, 50 | "onClick": "showToast" 51 | }, 52 | { 53 | "onClick": "showToast", 54 | "view": "RelativeLayout", 55 | "width": "match", 56 | "height": "48", 57 | "background": "#ff0000", 58 | "paddingLeft": "16", 59 | "paddingRight": "16", 60 | "child": [ 61 | { 62 | "view": "TextView", 63 | "text": "点击白色,产生子控件事件,\n点击红色,产生父控件事件", 64 | "height": "48", 65 | "width": "200", 66 | "textColor": "#444444", 67 | "marginLeft": "24", 68 | "textSize": "14", 69 | "gravity": "center", 70 | "onClick": "showToast2", 71 | "background": "#ffffff", 72 | "layout_centerVertical": true 73 | }, 74 | { 75 | "view": "TextView", 76 | "width": "wrap", 77 | "text": ">", 78 | "textColor": "#444444", 79 | "layout_alignParentRight": "true", 80 | "layout_centerVertical": true 81 | } 82 | ] 83 | }, 84 | { 85 | "view": "localComponent", 86 | "data": { 87 | "text": "application里,全局定义了一些component组件,查看代码便知", 88 | "textColor": "#666666" 89 | } 90 | } 91 | ] 92 | } 93 | ] 94 | } 95 | } -------------------------------------------------------------------------------- /sample/src/main/assets/headComponent.json: -------------------------------------------------------------------------------- 1 | { 2 | "head": { 3 | "process": "AndroidLayout", 4 | "components": [ 5 | { 6 | 7 | 8 | "name": "headComponent", 9 | "view": "RelativeLayout", 10 | "width": "match", 11 | "height": "48", 12 | "background": "#6fa8dc", 13 | "child": [ 14 | { 15 | "view": "TextView", 16 | "text": "这是无参数的head组件", 17 | "textColor": "#666666", 18 | "marginLeft": "24", 19 | "textSize": "14", 20 | "layout_centerVertical": true 21 | } 22 | ] 23 | 24 | }, 25 | { 26 | "name": "headComponent2", 27 | "template": { 28 | "view": "RelativeLayout", 29 | "width": "match", 30 | "height": "48", 31 | "background": "#6fa8dc", 32 | "child": [ 33 | { 34 | "view": "TextView", 35 | "text": "&text", 36 | "textColor": "&textColor", 37 | "textSize": "&textSize", 38 | "marginLeft": "24", 39 | "background": "&tvbackground", 40 | "layout_centerVertical": true 41 | }, 42 | { 43 | "view": "ImageView", 44 | "width": "20", 45 | "height": "20", 46 | "marginLeft": "44", 47 | "src": "&img", 48 | "visibility": "visible", 49 | "background": "&tvbackground", 50 | "layout_centerVertical": true, 51 | "layout_alignParentRight": true 52 | } 53 | ] 54 | } 55 | } 56 | ] 57 | }, 58 | "template": { 59 | "view": "verticalLayout", 60 | "width": "match", 61 | "height": "match", 62 | "background": "#f6f6f6", 63 | "child": [ 64 | { 65 | "view": "refreshBar" 66 | }, 67 | { 68 | "view": "scrollView", 69 | "width": "match", 70 | "height": "match", 71 | "visibility": "visible", 72 | "child": [ 73 | { 74 | "view": "localComponent2", 75 | "data": { 76 | "text": "动态组件" 77 | } 78 | }, 79 | { 80 | "view": "headComponent" 81 | }, 82 | { 83 | "view": "headComponent2", 84 | "background": "#f03838", 85 | "data": { 86 | "text": "这是有参数的head组件", 87 | "textColor": "#fff", 88 | "textSize": "18", 89 | "tvbackground": "#e1e1e1", 90 | "img": "http://onpxz5rdd.bkt.clouddn.com/ic_arrow_right_666.png", 91 | "isShowArrow": "visible" 92 | } 93 | } 94 | ] 95 | } 96 | ] 97 | } 98 | } -------------------------------------------------------------------------------- /sample/src/main/assets/images.json: -------------------------------------------------------------------------------- 1 | { 2 | "head": { 3 | "process": "AndroidLayout", 4 | "component": [ 5 | { 6 | "name": "sale", 7 | "view": "RelativeLayout", 8 | "width": "match", 9 | "height": "120dp", 10 | "margin": "8dp", 11 | "child": [ 12 | { 13 | "view": "ImageView", 14 | "width": "match", 15 | "height": "match", 16 | "src": "&src" 17 | } 18 | ] 19 | } 20 | ] 21 | }, 22 | "template": { 23 | "view": "scrollView", 24 | "width": "match", 25 | "height": "match", 26 | "background": "#f6f6f6", 27 | "child": [ 28 | { 29 | "view": "refreshBar" 30 | }, 31 | { 32 | "view": "line" 33 | }, 34 | { 35 | "name": "ver", 36 | "view": "verticalLayout", 37 | "width": "match", 38 | "height": "match", 39 | "gravity": "center", 40 | "child": [ 41 | { 42 | "name": "imagePane", 43 | "view": "horizonLayout", 44 | "width": "match_parent", 45 | "height": "wrap_content", 46 | "background": "#ffffff", 47 | "paddingLeft": "12dp", 48 | "paddingRight": "12dp", 49 | "paddingTop": "16", 50 | "paddingBottom": "10dp", 51 | "child": [ 52 | { 53 | "view": "ImageView", 54 | "src": "http://img.sanjiang.com/image/20173/1/image1488349927926.jpg", 55 | "width": "74dp", 56 | "height": "74dp", 57 | "margin": "5dp" 58 | }, 59 | { 60 | "view": "ImageView", 61 | "src": "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=232163874,2153671052&fm=58", 62 | "width": "74dp", 63 | "height": "74dp", 64 | "margin": "5dp" 65 | } 66 | ] 67 | }, 68 | { 69 | "view": "sale", 70 | "data": { 71 | "src": "http://img5.imgtn.bdimg.com/it/u=611483611,2895064642&fm=23&gp=0.jpg" 72 | } 73 | }, 74 | { 75 | "view": "sale", 76 | "data": { 77 | "src": "http://img0.imgtn.bdimg.com/it/u=1679155983,1401231999&fm=23&gp=0.jpg" 78 | } 79 | }, 80 | { 81 | "view": "sale", 82 | "data": { 83 | "src": "http://img4.imgtn.bdimg.com/it/u=1192943581,2431673841&fm=23&gp=0.jpg" 84 | } 85 | }, 86 | { 87 | "view": "sale", 88 | "data": { 89 | "src": "http://img4.imgtn.bdimg.com/it/u=270564085,356446953&fm=23&gp=0.jpg" 90 | } 91 | }, 92 | { 93 | "view": "sale", 94 | "data": { 95 | "src": "http://img1.imgtn.bdimg.com/it/u=2452165850,2398553721&fm=23&gp=0.jpg" 96 | } 97 | } 98 | ] 99 | } 100 | ] 101 | } 102 | } -------------------------------------------------------------------------------- /sample/src/main/assets/main.json: -------------------------------------------------------------------------------- 1 | { 2 | "head": { 3 | "process": "AndroidLayout", 4 | "components": [ 5 | { 6 | 7 | 8 | "name": "pane", 9 | "view": "TextView", 10 | "width": "250dp", 11 | "height": "60dp", 12 | "text": "&text", 13 | "gravity": "center", 14 | "margin": "10", 15 | "textSize": "18", 16 | "textColor": "#fff", 17 | "background": "&background", 18 | "visibility": "&visibility", 19 | "onClick": "jumpToActivity" 20 | } 21 | 22 | ] 23 | }, 24 | "template": { 25 | "view": "scrollView", 26 | "width": "match", 27 | "height": "match", 28 | "background": "#f6f6f6", 29 | "child": [ 30 | { 31 | "view": "refreshBar" 32 | }, 33 | { 34 | "view": "line" 35 | }, 36 | { 37 | "name": "ver", 38 | "view": "verticalLayout", 39 | "width": "match", 40 | "height": "match", 41 | "gravity": "center", 42 | "child": [ 43 | { 44 | "name": "name1", 45 | "view": "pane", 46 | "data": { 47 | "text": "从本地加载json文件渲染视图", 48 | "background": "#ff03A9F4", 49 | "route": "yiewdemo.JsonFromLocalActivity" 50 | } 51 | }, 52 | 53 | { 54 | "view": "pane", 55 | "data": { 56 | "background": "#ff4CAF50", 57 | "text": "使用Yiew代码创建视图", 58 | "route": "yiewdemo.YiewCodeActivity" 59 | } 60 | }, 61 | { 62 | "view": "pane", 63 | "data": { 64 | "background": "#fb9236", 65 | "text": "自定义component 用法 \n与 onClick事件", 66 | "route": "yiewdemo.FeatureActivity" 67 | } 68 | }, 69 | { 70 | "view": "pane", 71 | "data": { 72 | "background": "#d9Ff5858", 73 | "text": "yiew虚拟节点的使用,更新虚拟节点,就能更新相应的view", 74 | "route": "yiewdemo.VirtualVNodeActivity" 75 | } 76 | }, 77 | { 78 | "view": "pane", 79 | "data": { 80 | "background": "#ffF44336", 81 | "text": "head组件 的使用", 82 | "route": "yiewdemo.HeadComponentActivity" 83 | } 84 | }, 85 | { 86 | "view": "pane", 87 | "data": { 88 | "background": "#d9Ff5858", 89 | "text": "image 的使用", 90 | "route": "yiewdemo.JsonImageActivity" 91 | } 92 | }, 93 | { 94 | "view": "pane", 95 | "data": { 96 | "background": "#d9Ff5858", 97 | "text": "list 的使用", 98 | "route": "yiewdemo.SalesActivity" 99 | } 100 | } 101 | ] 102 | } 103 | ] 104 | } 105 | } -------------------------------------------------------------------------------- /sample/src/main/assets/sales.json: -------------------------------------------------------------------------------- 1 | { 2 | "head": { 3 | "process": "AndroidLayout", 4 | "components": [ 5 | { 6 | 7 | 8 | "name": "sale", 9 | "view": "RelativeLayout", 10 | "width": "match", 11 | "height": "120dp", 12 | "background": "#999999", 13 | "margin": "8dp", 14 | "child": [ 15 | { 16 | "view": "ImageView", 17 | "width": "match", 18 | "height": "match", 19 | "src": "&src" 20 | } 21 | ] 22 | } 23 | 24 | ] 25 | }, 26 | "template": { 27 | "view": "RelativeLayout", 28 | "width": "match", 29 | "height": "match", 30 | "background": "#f6f6f6", 31 | "child": [ 32 | { 33 | "view": "refreshBar" 34 | }, 35 | { 36 | "view": "line" 37 | }, 38 | { 39 | 40 | "view": "RecyclerView", 41 | "width": "match", 42 | "height": "match", 43 | "itemLayout": "sale", 44 | "data": { 45 | "list": [ 46 | { 47 | "src": "https://ss0.bdstatic.com/-0U0bnSm1A5BphGlnYG/tam-ogel/1d68b8f42a077e5fc13dd53282b884ad_121_121.jpg" 48 | }, 49 | { 50 | "src": "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=922240654,3133047221&fm=58" 51 | }, 52 | { 53 | "src": "https://ss0.bdstatic.com/-0U0bnSm1A5BphGlnYG/tam-ogel/674149bf80b4ed8ff9b94493c4cf7b8e_255_96.jpg" 54 | }, 55 | { 56 | "src": "https://ss0.bdstatic.com/-0U0bnSm1A5BphGlnYG/tam-ogel/1d68b8f42a077e5fc13dd53282b884ad_121_121.jpg" 57 | }, 58 | { 59 | "src": "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=922240654,3133047221&fm=58" 60 | }, 61 | { 62 | "src": "https://ss0.bdstatic.com/-0U0bnSm1A5BphGlnYG/tam-ogel/674149bf80b4ed8ff9b94493c4cf7b8e_255_96.jpg" 63 | },{ 64 | "src": "https://ss0.bdstatic.com/-0U0bnSm1A5BphGlnYG/tam-ogel/1d68b8f42a077e5fc13dd53282b884ad_121_121.jpg" 65 | }, 66 | { 67 | "src": "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=922240654,3133047221&fm=58" 68 | }, 69 | { 70 | "src": "https://ss0.bdstatic.com/-0U0bnSm1A5BphGlnYG/tam-ogel/674149bf80b4ed8ff9b94493c4cf7b8e_255_96.jpg" 71 | } 72 | ] 73 | } 74 | } 75 | ] 76 | } 77 | } -------------------------------------------------------------------------------- /sample/src/main/assets/simple.json: -------------------------------------------------------------------------------- 1 | { 2 | "head": { 3 | "process": "AndroidLayout" 4 | }, 5 | "template": { 6 | "view": "verticalLayout", 7 | "width": "match", 8 | "height": "match", 9 | "background": "#f6f6f6", 10 | "child": [ 11 | { 12 | "view": "TextView", 13 | "text": "页面的简单使用", 14 | "width": "120dp", 15 | "height": "30dp", 16 | "textColor": "#444444", 17 | "padding": "16dp", 18 | "textSize": "16" 19 | } 20 | ] 21 | } 22 | } -------------------------------------------------------------------------------- /sample/src/main/assets/virtual.json: -------------------------------------------------------------------------------- 1 | { 2 | "head": { 3 | "process": "AndroidLayout" 4 | }, 5 | "template": { 6 | "view": "verticalLayout", 7 | "width": "match", 8 | "height": "match", 9 | "background": "#f6f6f6", 10 | "child": [ 11 | { 12 | "view": "refreshBar" 13 | }, 14 | { 15 | "view": "scrollView", 16 | "width": "match", 17 | "height": "match", 18 | "child": [ 19 | { 20 | "view": "View", 21 | "width": "match", 22 | "height": "20" 23 | }, 24 | { 25 | "name": "mobilePane", 26 | "view": "RelativeLayout", 27 | "width": "match", 28 | "height": "48", 29 | "background": "#ffffff", 30 | "child": [ 31 | { 32 | "view": "TextView", 33 | "text": "changeSelf", 34 | "onClick": "changeSelf", 35 | "textColor": "#666666", 36 | "marginLeft": "24", 37 | "textSize": "14", 38 | "layout_centerVertical": true 39 | }, 40 | { 41 | "view": "TextView", 42 | "width": "wrap", 43 | "text": "", 44 | "textColor": "#666666", 45 | "layout_alignParentRight": true, 46 | "marginRight": "24", 47 | "layout_centerVertical": true 48 | } 49 | ] 50 | } 51 | , 52 | { 53 | "view": "View", 54 | "width": "match", 55 | "height": "1" 56 | }, 57 | { 58 | "name": "contactPane", 59 | "view": "RelativeLayout", 60 | "width": "match", 61 | "height": "48", 62 | "background": "#ffffff", 63 | "child": [ 64 | { 65 | "view": "TextView", 66 | "text": "changeOther", 67 | "textColor": "#666666", 68 | "marginLeft": "24", 69 | "textSize": "14", 70 | "onClick": "changeOther", 71 | "layout_centerVertical": true 72 | }, 73 | { 74 | "name": "otherText", 75 | "view": "TextView", 76 | "width": "wrap", 77 | "text": "shen", 78 | "textColor": "#666666", 79 | "layout_alignParentRight": true, 80 | "marginRight": "24", 81 | "layout_centerVertical": true 82 | } 83 | ] 84 | } 85 | ] 86 | } 87 | ] 88 | } 89 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/avocarrot/json2view/sample/App.java: -------------------------------------------------------------------------------- 1 | package com.avocarrot.json2view.sample; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.ImageView; 8 | 9 | import com.apkfuns.logutils.LogUtils; 10 | import com.arthas.xjsonview.XViewComponent; 11 | import com.arthas.xjsonview.XViewEngine; 12 | import com.arthas.xjsonview.XViewImageAdapter; 13 | import com.arthas.xjsonview.XiewConfig; 14 | import com.arthas.xjsonview.bean.XViewBase; 15 | import com.arthas.xjsonview.bean.XViewBody; 16 | import com.bumptech.glide.Glide; 17 | import com.lzy.okgo.OkGo; 18 | import com.lzy.okgo.cache.CacheMode; 19 | import com.taobao.weex.InitConfig; 20 | import com.taobao.weex.WXSDKEngine; 21 | 22 | import java.util.logging.Level; 23 | 24 | /** 25 | * Created by zhangyn on 17/4/1. 26 | */ 27 | 28 | public class App extends Application { 29 | @Override 30 | public void onCreate() { 31 | super.onCreate(); 32 | 33 | InitConfig config=new InitConfig.Builder().setImgAdapter(new ImageAdapter()).build(); 34 | WXSDKEngine.initialize(this,config); 35 | 36 | OkGo.init(this); 37 | OkGo.getInstance() 38 | 39 | // 打开该调试开关,打印级别INFO,并不是异常,是为了显眼,不需要就不要加入该行 40 | // 最后的true表示是否打印okgo的内部异常,一般打开方便调试错误 41 | .debug("OkGo", Level.INFO, true) 42 | 43 | //如果使用默认的 60秒,以下三行也不需要传 44 | .setConnectTimeout(OkGo.DEFAULT_MILLISECONDS) //全局的连接超时时间 45 | .setReadTimeOut(OkGo.DEFAULT_MILLISECONDS) //全局的读取超时时间 46 | .setWriteTimeOut(OkGo.DEFAULT_MILLISECONDS) //全局的写入超时时间 47 | 48 | .setCacheMode(CacheMode.NO_CACHE); 49 | 50 | LogUtils.getLogConfig() 51 | .configAllowLog(true) 52 | .configTagPrefix("MyAppName") 53 | .configShowBorders(true) 54 | .configFormatTag("%d{HH:mm:ss:SSS} %t %c{-5}"); 55 | 56 | XViewImageAdapter imageAdapter = new XViewImageAdapter() { 57 | 58 | @Override 59 | public void display(ImageView view, String src, XViewBase yiew) { 60 | Glide.with(view.getContext()). 61 | load(yiew.src). 62 | crossFade(400) 63 | .into(view); 64 | } 65 | }; 66 | 67 | XiewConfig.setImageAdapter(imageAdapter); 68 | 69 | 70 | XiewConfig.addComponent("refreshBar", new XViewComponent() { 71 | 72 | @Override 73 | public View createComponentView(Context context, ViewGroup parent, XViewBody yiew ) { 74 | 75 | 76 | XViewBody template = XViewBody.create(XViewBody.RelativeLayout, XViewBody.MATCH,"48dp") ; 77 | 78 | XViewBody TextView = XViewBody.create(XViewBody.TextView, XViewBody.MATCH, XViewBody.MATCH) ; 79 | template.addChild(TextView); 80 | TextView.layout_centerInParent=true; 81 | TextView.text="刷新"; 82 | TextView.gravity="center"; 83 | TextView.onClick ="refresh"; 84 | TextView.textColor="#333333"; 85 | TextView.background="#ffffff"; 86 | 87 | 88 | 89 | View yiew1 = XViewEngine.createView(context, parent, template); 90 | return yiew1; 91 | } 92 | 93 | @Override 94 | public void render(XViewBody yiew) { 95 | 96 | } 97 | }); 98 | 99 | 100 | 101 | XiewConfig.addComponent("line", new XViewComponent() { 102 | 103 | @Override 104 | public View createComponentView(Context context, ViewGroup parent, XViewBody yiew ) { 105 | 106 | XViewBody dv = XViewBody.create(XViewBody.View, XViewBody.MATCH,"1px") ; 107 | dv.background = "#dddddd"; 108 | View yiew1 = XViewEngine.createView(context, parent, dv); 109 | return yiew1; 110 | } 111 | 112 | @Override 113 | public void render(XViewBody yiew) { 114 | 115 | } 116 | }); 117 | 118 | 119 | 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /sample/src/main/java/com/avocarrot/json2view/sample/ImageAdapter.java: -------------------------------------------------------------------------------- 1 | package com.avocarrot.json2view.sample; 2 | import android.widget.ImageView; 3 | import com.taobao.weex.adapter.IWXImgLoaderAdapter; 4 | import com.taobao.weex.common.WXImageStrategy; 5 | import com.taobao.weex.dom.WXImageQuality; 6 | /** 7 | * Created by lixinke on 16/6/1. 8 | */ 9 | public class ImageAdapter implements IWXImgLoaderAdapter { 10 | @Override 11 | public void setImage(String url, ImageView view, WXImageQuality quality, WXImageStrategy strategy) { 12 | //实现你自己的图片下载,否则图片无法显示。 13 | } 14 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/avocarrot/json2view/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.avocarrot.json2view.sample; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.view.View; 8 | 9 | import com.apkfuns.logutils.LogUtils; 10 | import com.arthas.xjsonview.XViewMain; 11 | import com.arthas.xjsonview.bean.XView; 12 | import com.arthas.xjsonview.bean.XViewBody; 13 | import com.lzy.okgo.OkGo; 14 | import com.lzy.okgo.callback.StringCallback; 15 | 16 | import java.util.Map; 17 | 18 | import okhttp3.Call; 19 | import okhttp3.Response; 20 | import yiewdemo.Util; 21 | 22 | public class MainActivity extends AppCompatActivity { 23 | 24 | 25 | private Context context; 26 | 27 | @Override 28 | protected void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | 31 | 32 | context = this; 33 | 34 | // LogUtils.d("aaaa"); 35 | // String s = Util.readFile(context, "main.json"); 36 | // LogUtils.d("aaaa"+s); 37 | // Yiew yiew = gson.fromJson(s, Yiew.class); 38 | // 39 | // 40 | // 41 | // Log.d("syb","get yiewbean"); 42 | // 43 | // 44 | // View aa = YiewEngine.createComponentView(context, null, yiew, null); 45 | 46 | 47 | // setContentView(aa); 48 | 49 | load(); 50 | } 51 | 52 | private void load() { 53 | OkGo.get("http://193.0.1.157:9999/main.json") // 请求方式和请求url 54 | 55 | .execute(new StringCallback() { 56 | @Override 57 | public void onSuccess(String s, Call call, Response response) { 58 | 59 | XView yiew_1 = Util.gson.fromJson(s, XView.class); 60 | 61 | View aa = XViewMain.startProcess(context, yiew_1 ); 62 | 63 | setContentView(aa); 64 | 65 | 66 | 67 | } 68 | }); 69 | } 70 | 71 | 72 | 73 | 74 | public void refresh() { 75 | 76 | load(); 77 | 78 | } 79 | 80 | public void jumpToActivity(XViewBody yiew) { 81 | LogUtils.d("jumpToActivity"); 82 | Map data = yiew.data; 83 | LogUtils.d(data); 84 | Object name = data.get("route"); 85 | LogUtils.d(name); 86 | try { 87 | Class aClass = Class.forName(name.toString()); 88 | startActivity(new Intent(context,aClass)); 89 | } catch (ClassNotFoundException e) { 90 | e.printStackTrace(); 91 | } 92 | 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /sample/src/main/java/flex/FlexActivity.java: -------------------------------------------------------------------------------- 1 | package flex; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | 6 | import com.avocarrot.json2view.sample.R; 7 | 8 | public class FlexActivity extends AppCompatActivity { 9 | 10 | 11 | private FlexActivity context; 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | 17 | 18 | context = this; 19 | 20 | 21 | setContentView(R.layout.flexlayout); 22 | 23 | } 24 | 25 | 26 | 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /sample/src/main/java/weexact/WeexActivity1.java: -------------------------------------------------------------------------------- 1 | package weexact; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | 6 | import com.avocarrot.json2view.sample.R; 7 | 8 | public class WeexActivity1 extends AppCompatActivity { 9 | 10 | 11 | private WeexActivity1 context; 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | 17 | 18 | context = this; 19 | 20 | 21 | setContentView(R.layout.flexlayout); 22 | 23 | } 24 | 25 | 26 | 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /sample/src/main/java/yiewdemo/FeatureActivity.java: -------------------------------------------------------------------------------- 1 | package yiewdemo; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.Toast; 9 | 10 | import com.apkfuns.logutils.LogUtils; 11 | import com.arthas.xjsonview.XViewComponent; 12 | import com.arthas.xjsonview.XViewMain; 13 | import com.arthas.xjsonview.SimpleXViewComponent; 14 | import com.arthas.xjsonview.XiewConfig; 15 | import com.arthas.xjsonview.XViewEngine; 16 | import com.arthas.xjsonview.bean.XViewBody; 17 | import com.arthas.xjsonview.bean.XView; 18 | import com.lzy.okgo.OkGo; 19 | import com.lzy.okgo.callback.StringCallback; 20 | 21 | import okhttp3.Call; 22 | import okhttp3.Response; 23 | 24 | public class FeatureActivity extends AppCompatActivity { 25 | 26 | 27 | private FeatureActivity context; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | 33 | 34 | context = this; 35 | 36 | 37 | XiewConfig.addComponent("localComponent", new SimpleXViewComponent() { 38 | @Override 39 | public void render(XViewBody yiew) { 40 | 41 | } 42 | 43 | @Override 44 | public XViewBody createTemplate(Context context, ViewGroup parent, XViewBody yiew) { 45 | XViewBody template = XViewBody.create(XViewBody.RelativeLayout, XViewBody.MATCH, "48dp"); 46 | 47 | 48 | template.background = "#ffFFEB3B"; 49 | XViewBody tv = XViewBody.create(XViewBody.TextView, XViewBody.MATCH, XViewBody.MATCH); 50 | template.addChild(tv); 51 | 52 | //子控件赋值 53 | 54 | 55 | tv.text = yiew.getData("text", "这是一个组件"); 56 | tv.textColor = yiew.getData("textColor", "#444444"); 57 | 58 | tv.marginLeft = "20dp"; 59 | tv.gravity = yiew.getData("gravity", "CENTER_VERTICAL"); 60 | 61 | return template; 62 | 63 | 64 | } 65 | }); 66 | XiewConfig.addComponent("localComponent2", new XViewComponent() { 67 | @Override 68 | public View createComponentView(Context context, ViewGroup parent, XViewBody yiew) { 69 | XViewBody template = XViewBody.create(XViewBody.RelativeLayout, XViewBody.MATCH, "48dp"); 70 | 71 | template.background = "#f6f6f6"; 72 | //原属性覆盖 73 | 74 | 75 | XViewBody tv = XViewBody.create(XViewBody.TextView, XViewBody.MATCH, XViewBody.MATCH); 76 | template.addChild(tv); 77 | 78 | //子控件赋值 79 | 80 | 81 | tv.text = yiew.getData("text", "这是一个组件"); 82 | tv.textColor = yiew.getData("textColor", "#444444"); 83 | 84 | tv.marginLeft = "20dp"; 85 | tv.gravity = yiew.getData("gravity", "CENTER"); 86 | 87 | 88 | yiew.setComponentTemplate(template); 89 | View yiew1 = XViewEngine.createView(context, parent, yiew); 90 | return yiew1; 91 | 92 | } 93 | 94 | @Override 95 | public void render(XViewBody yiew) { 96 | 97 | } 98 | }); 99 | 100 | 101 | load(); 102 | } 103 | 104 | private void load() { 105 | OkGo.get("http://193.0.1.157:8080/feature.json") // 请求方式和请求url 106 | 107 | .execute(new StringCallback() { 108 | @Override 109 | public void onSuccess(String s, Call call, Response response) { 110 | 111 | XView yiew_1 = Util.gson.fromJson(s, XView.class); 112 | 113 | View contentView = XViewMain.startProcess(context, yiew_1); 114 | setContentView(contentView); 115 | 116 | 117 | } 118 | }); 119 | } 120 | 121 | 122 | public void refresh() { 123 | 124 | load(); 125 | 126 | } 127 | 128 | public void showToast() { 129 | 130 | LogUtils.d("showToast"); 131 | Toast.makeText(context, "showToast", 1).show(); 132 | 133 | } 134 | 135 | public void showToast2() { 136 | 137 | LogUtils.d("showToast"); 138 | Toast.makeText(context, "showToast2", 1).show(); 139 | 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /sample/src/main/java/yiewdemo/HeadComponentActivity.java: -------------------------------------------------------------------------------- 1 | package yiewdemo; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.view.View; 6 | import android.widget.Toast; 7 | 8 | import com.apkfuns.logutils.LogUtils; 9 | import com.arthas.xjsonview.XViewMain; 10 | import com.arthas.xjsonview.bean.XView; 11 | import com.lzy.okgo.OkGo; 12 | import com.lzy.okgo.callback.StringCallback; 13 | 14 | import okhttp3.Call; 15 | import okhttp3.Response; 16 | 17 | public class HeadComponentActivity extends AppCompatActivity { 18 | 19 | 20 | private HeadComponentActivity context; 21 | 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | 26 | 27 | context = this; 28 | 29 | 30 | 31 | load(); 32 | } 33 | 34 | private void load() { 35 | OkGo.get("http://193.0.1.157:8080/headcomponent.json") // 请求方式和请求url 36 | 37 | .execute(new StringCallback() { 38 | @Override 39 | public void onSuccess(String s, Call call, Response response) { 40 | 41 | XView yiewResp = Util.gson.fromJson(s, XView.class); 42 | 43 | View contentView = XViewMain.startProcess(context, yiewResp); 44 | 45 | setContentView(contentView); 46 | 47 | 48 | } 49 | }); 50 | } 51 | 52 | 53 | public void refresh() { 54 | 55 | load(); 56 | 57 | } 58 | 59 | public void showToast() { 60 | 61 | LogUtils.d("showToast"); 62 | Toast.makeText(context, "showToast", 1).show(); 63 | 64 | } 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /sample/src/main/java/yiewdemo/JsonFromLocalActivity.java: -------------------------------------------------------------------------------- 1 | package yiewdemo; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.view.View; 6 | 7 | import com.arthas.xjsonview.XViewMain; 8 | import com.arthas.xjsonview.bean.XView; 9 | import com.lzy.okgo.OkGo; 10 | import com.lzy.okgo.callback.StringCallback; 11 | 12 | import okhttp3.Call; 13 | import okhttp3.Response; 14 | 15 | public class JsonFromLocalActivity extends AppCompatActivity { 16 | 17 | 18 | private JsonFromLocalActivity context; 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | 24 | 25 | context = this; 26 | 27 | String s = Util.readFile(context, "complaintDetail.json"); 28 | XView yiew_1 = Util.gson.fromJson(s, XView.class); 29 | 30 | View contentView = XViewMain.startProcess(context, yiew_1 ); 31 | 32 | setContentView(contentView); 33 | 34 | 35 | 36 | // load(); 37 | } 38 | 39 | private void load() { 40 | OkGo.get("http://193.0.1.157:8080/complaintDetail.json") // 请求方式和请求url 41 | 42 | .execute(new StringCallback() { 43 | @Override 44 | public void onSuccess(String s, Call call, Response response) { 45 | 46 | XView yiew_1 = Util.gson.fromJson(s, XView.class); 47 | 48 | View contentView = XViewMain.startProcess(context, yiew_1 ); 49 | setContentView(contentView); 50 | 51 | 52 | 53 | } 54 | }); 55 | } 56 | 57 | 58 | 59 | 60 | public void refresh() { 61 | 62 | load(); 63 | 64 | } 65 | // public void gotoDataSource() { 66 | // startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://onzew89e9.bkt.clouddn.com/complaintDetail.json"))); 67 | // } 68 | 69 | 70 | } 71 | -------------------------------------------------------------------------------- /sample/src/main/java/yiewdemo/JsonImageActivity.java: -------------------------------------------------------------------------------- 1 | package yiewdemo; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.view.View; 6 | 7 | import com.arthas.xjsonview.XViewMain; 8 | import com.arthas.xjsonview.bean.XView; 9 | import com.lzy.okgo.OkGo; 10 | import com.lzy.okgo.callback.StringCallback; 11 | 12 | import okhttp3.Call; 13 | import okhttp3.Response; 14 | 15 | public class JsonImageActivity extends AppCompatActivity { 16 | 17 | 18 | private JsonImageActivity context; 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | 24 | 25 | context = this; 26 | 27 | 28 | 29 | 30 | load(); 31 | 32 | } 33 | 34 | private void load() { 35 | OkGo.get("http://193.0.1.157:8080/images.json") // 请求方式和请求url 36 | 37 | .execute(new StringCallback() { 38 | @Override 39 | public void onSuccess(String s, Call call, Response response) { 40 | XView yiew_1 = Util.gson.fromJson(s, XView.class); 41 | 42 | View contentView = XViewMain.startProcess(context, yiew_1 ); 43 | setContentView(contentView); 44 | 45 | 46 | 47 | } 48 | }); 49 | } 50 | 51 | 52 | 53 | 54 | public void refresh() { 55 | 56 | load(); 57 | 58 | } 59 | 60 | 61 | 62 | 63 | } 64 | -------------------------------------------------------------------------------- /sample/src/main/java/yiewdemo/SalesActivity.java: -------------------------------------------------------------------------------- 1 | package yiewdemo; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.view.View; 8 | 9 | import com.apkfuns.logutils.LogUtils; 10 | import com.arthas.xjsonview.XViewMain; 11 | import com.arthas.xjsonview.bean.XView; 12 | import com.arthas.xjsonview.bean.XViewBody; 13 | import com.lzy.okgo.OkGo; 14 | import com.lzy.okgo.callback.StringCallback; 15 | 16 | import java.util.Map; 17 | 18 | import okhttp3.Call; 19 | import okhttp3.Response; 20 | 21 | public class SalesActivity extends AppCompatActivity { 22 | 23 | 24 | private Context context; 25 | 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | 30 | 31 | context = this; 32 | 33 | 34 | load(); 35 | } 36 | 37 | private void load() { 38 | OkGo.get("http://193.0.1.157:9999/sales.json") // 请求方式和请求url 39 | 40 | .execute(new StringCallback() { 41 | @Override 42 | public void onSuccess(String s, Call call, Response response) { 43 | 44 | XView yiew_1 = Util.gson.fromJson(s, XView.class); 45 | 46 | View aa = XViewMain.startProcess(context, yiew_1 ); 47 | 48 | setContentView(aa); 49 | 50 | 51 | 52 | } 53 | }); 54 | } 55 | 56 | 57 | 58 | 59 | public void refresh() { 60 | 61 | load(); 62 | 63 | } 64 | 65 | public void jumpToActivity(XViewBody yiew) { 66 | LogUtils.d("jumpToActivity"); 67 | Map data = yiew.data; 68 | LogUtils.d(data); 69 | Object name = data.get("route"); 70 | LogUtils.d(name); 71 | try { 72 | Class aClass = Class.forName(name.toString()); 73 | startActivity(new Intent(context,aClass)); 74 | } catch (ClassNotFoundException e) { 75 | e.printStackTrace(); 76 | } 77 | 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /sample/src/main/java/yiewdemo/Util.java: -------------------------------------------------------------------------------- 1 | package yiewdemo; 2 | 3 | import android.content.Context; 4 | 5 | import com.google.gson.Gson; 6 | 7 | import java.io.BufferedReader; 8 | import java.io.InputStream; 9 | import java.io.InputStreamReader; 10 | 11 | /** 12 | * Created by zhangyn on 17/4/1. 13 | */ 14 | 15 | public class Util { 16 | public final static Gson gson = new Gson(); 17 | 18 | /** 19 | * Helper function to load file from assets 20 | */ 21 | public static String readFile( Context context,String fileName) { 22 | StringBuilder returnString = new StringBuilder(); 23 | InputStream fIn = null; 24 | InputStreamReader isr = null; 25 | BufferedReader input = null; 26 | try { 27 | fIn = context.getResources().getAssets().open(fileName); 28 | isr = new InputStreamReader(fIn); 29 | input = new BufferedReader(isr); 30 | String line; 31 | while ((line = input.readLine()) != null) { 32 | returnString.append(line); 33 | } 34 | } catch (Exception e) { 35 | e.getMessage(); 36 | } finally { 37 | try { 38 | if (isr != null) isr.close(); 39 | if (fIn != null) fIn.close(); 40 | if (input != null) input.close(); 41 | } catch (Exception e2) { 42 | e2.getMessage(); 43 | } 44 | } 45 | return returnString.toString(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /sample/src/main/java/yiewdemo/VirtualVNodeActivity.java: -------------------------------------------------------------------------------- 1 | package yiewdemo; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.view.View; 6 | import android.widget.TextView; 7 | 8 | import com.apkfuns.logutils.LogUtils; 9 | import com.arthas.xjsonview.XViewMain; 10 | import com.arthas.xjsonview.bean.XViewBody; 11 | import com.arthas.xjsonview.bean.XView; 12 | import com.lzy.okgo.OkGo; 13 | import com.lzy.okgo.callback.StringCallback; 14 | 15 | import okhttp3.Call; 16 | import okhttp3.Response; 17 | 18 | public class VirtualVNodeActivity extends AppCompatActivity { 19 | 20 | 21 | private VirtualVNodeActivity context; 22 | 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | 28 | 29 | context = this; 30 | 31 | 32 | load(); 33 | } 34 | 35 | private void load() { 36 | OkGo.get("http://193.0.1.157:8080/virtual.json") // 请求方式和请求url 37 | 38 | .execute(new StringCallback() { 39 | @Override 40 | public void onSuccess(String s, Call call, Response response) { 41 | 42 | XView yiew_1 = Util.gson.fromJson(s, XView.class); 43 | 44 | View contentView = XViewMain.startProcess(context, yiew_1 ); 45 | setContentView(contentView); 46 | 47 | 48 | } 49 | }); 50 | } 51 | 52 | 53 | public void refresh() { 54 | 55 | load(); 56 | 57 | } 58 | 59 | public void changeSelf(XViewBody yiew) { 60 | LogUtils.d("changeSelf"); 61 | LogUtils.d("changeSelf"+yiew); 62 | TextView view = (TextView) yiew.getCurrentView(); 63 | view.setText("asd"); 64 | 65 | 66 | yiew.text = "azxczxczxc"; 67 | yiew.invalid(); 68 | } 69 | 70 | public void changeOther(XViewBody yiew) { 71 | XViewBody otherText = yiew.getYiewStore().getYiewByName("otherText"); 72 | TextView view = otherText.getCurrentView(); 73 | view.setText("124233434"); 74 | } 75 | 76 | 77 | } 78 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aarthas/android_Json2view/809039603ebae8b35c7fa45472c71244c20a18ce/sample/src/main/res/drawable-hdpi/icon.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aarthas/android_Json2view/809039603ebae8b35c7fa45472c71244c20a18ce/sample/src/main/res/drawable-mdpi/icon.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aarthas/android_Json2view/809039603ebae8b35c7fa45472c71244c20a18ce/sample/src/main/res/drawable-xhdpi/icon.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aarthas/android_Json2view/809039603ebae8b35c7fa45472c71244c20a18ce/sample/src/main/res/drawable-xxhdpi/icon.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable/sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aarthas/android_Json2view/809039603ebae8b35c7fa45472c71244c20a18ce/sample/src/main/res/drawable/sample.png -------------------------------------------------------------------------------- /sample/src/main/res/layout/aa.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 15 | 16 | 20 | 21 | 29 | 30 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/flexlayout.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 20 | 21 | 29 | 30 | 39 | 40 | 50 | 51 | 52 | 62 | 70 | 78 | 79 | 87 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/imageview.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | 25 | 26 | 30 | 31 | 39 | 40 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | json2view 5 | 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':sample', ':utils', ':XJsonViewLib', ':javaCodeGenerate' 2 | -------------------------------------------------------------------------------- /utils/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'groovy' 2 | 3 | repositories { 4 | mavenCentral() 5 | } 6 | 7 | dependencies { 8 | compile 'org.codehaus.groovy:groovy-all:2.1.6' 9 | } 10 | 11 | task runScript(dependsOn: 'classes', type: JavaExec) { 12 | description 'Run Groovy script' 13 | 14 | // Set main property to name of Groovy script class. 15 | main = 'ConvertXML2Json' 16 | 17 | // Set classpath for running the Groovy script. 18 | classpath = sourceSets.main.runtimeClasspath 19 | 20 | if (project.hasProperty('xml')) { 21 | // Pass command-line argument to script. 22 | args new File(".").absolutePath + File.separator + project.getProperty('xml') 23 | } 24 | } 25 | 26 | defaultTasks 'runScript' -------------------------------------------------------------------------------- /utils/src/main/groovy/ConvertXML2Json.groovy: -------------------------------------------------------------------------------- 1 | println() 2 | println "*********************** " 3 | println "*** ConvertXML2Json *** " 4 | println "Still in experimental mode :(" 5 | println() 6 | 7 | 8 | def inputFile = new File(this.args[0]) 9 | 10 | if (!inputFile.exists()) { 11 | println "The input file doesn't exist. Process incomplete | " + this.args[0] 12 | return 13 | } 14 | 15 | def layout = new XmlParser().parse(inputFile) 16 | 17 | println new groovy.json.JsonBuilder( createView(layout) ).toString(); 18 | 19 | View createView (node) { 20 | 21 | def name = ""; 22 | def properties = []; 23 | def views = []; 24 | 25 | name = node.name().toString(); 26 | if (name == "View") name = "android.view.View" 27 | 28 | node.attributes().each { t -> 29 | properties.push( createProperty(t) ) 30 | } 31 | 32 | node.value().each { t -> 33 | views.push( createView(t) ); 34 | } 35 | 36 | return new View( name, properties, views ); 37 | 38 | } 39 | 40 | Property createProperty (attribute) { 41 | 42 | def name = attribute.key.localPart; 43 | def type = "string"; 44 | def value = attribute.value; 45 | 46 | switch(name.toUpperCase()) { 47 | case "ID": 48 | case "LAYOUT_ABOVE": 49 | case "LAYOUT_ALIGNBASELINE": 50 | case "LAYOUT_ALIGNBOTTOM": 51 | case "LAYOUT_ALIGNEND": 52 | case "LAYOUT_ALIGNLEFT": 53 | case "LAYOUT_ALIGNRIGHT": 54 | case "LAYOUT_ALIGNSTART": 55 | case "LAYOUT_ALIGNTOP": 56 | case "LAYOUT_BELOW": 57 | case "LAYOUT_TOENDOF": 58 | case "LAYOUT_TOLEFTOF": 59 | case "LAYOUT_TORIGHTOF": 60 | case "LAYOUT_TOSTARTOF": 61 | type = "ref"; 62 | try { 63 | value = value.split("/")[1]; 64 | } catch (Exception e) {} 65 | break; 66 | case "BACKGROUND": 67 | case "TEXTCOLOR": 68 | type = "color"; 69 | break; 70 | case "LAYOUT_WIDTH": 71 | case "LAYOUT_HEIGHT": 72 | case "PADDING_LEFT": 73 | case "PADDING_RIGHT": 74 | case "PADDING_TOP": 75 | case "PADDING_BOTTOM": 76 | case "PADDING": 77 | case "TEXTSIZE": 78 | case "LAYOUT_MARGINLEFT": 79 | case "LAYOUT_MARGINRIGHT": 80 | case "LAYOUT_MARGINTOP": 81 | case "LAYOUT_MARGINBOTTOM": 82 | case "LAYOUT_MARGIN": 83 | case "MINWIDTH": 84 | case "MINHEIGHT": 85 | type = "dimen"; 86 | break; 87 | case "LAYOUT_ALIGNWITHPARENTIFMISSING": 88 | case "LAYOUT_CENTERHORIZONTAL": 89 | case "LAYOUT_CENTERINPARENT": 90 | case "LAYOUT_CENTERVERTICAL": 91 | case "LAYOUT_ALIGNPARENTBOTTOM": 92 | case "LAYOUT_ALIGNPARENTEND": 93 | case "LAYOUT_ALIGNPARENTLEFT": 94 | case "LAYOUT_ALIGNPARENTRIGHT": 95 | case "LAYOUT_ALIGNPARENTSTART": 96 | case "LAYOUT_ALIGNPARENTTOP": 97 | type = "BOOLEAN"; 98 | break; 99 | case "LAYOUT_WEIGHT": 100 | type = "float"; 101 | break; 102 | case "SCALETYPE": 103 | value = splitCamelCase(value).replaceAll(" ", "_"); 104 | break; 105 | } 106 | 107 | return new Property( name, type, value ); 108 | 109 | } 110 | 111 | String splitCamelCase(String s) { 112 | return s.replaceAll( 113 | String.format("%s|%s|%s", 114 | "(?<=[A-Z])(?=[A-Z][a-z])", 115 | "(?<=[^A-Z])(?=[A-Z])", 116 | "(?<=[A-Za-z])(?=[^A-Za-z])" 117 | ), 118 | " " 119 | ); 120 | } 121 | 122 | @groovy.transform.Canonical 123 | @groovy.transform.ToString(excludes='views') 124 | class View { 125 | String widget 126 | List properties 127 | List views 128 | } 129 | @groovy.transform.Canonical 130 | class Property { 131 | String name 132 | String type 133 | String value 134 | } 135 | --------------------------------------------------------------------------------