From e528667e7c0d02025888695fabc7b163dc2cccf4 Mon Sep 17 00:00:00 2001 From: Aditya Sharat Date: Sun, 13 Jan 2019 00:03:22 +0000 Subject: [PATCH 01/19] fix the version name and version code of modules --- build.gradle | 4 ++-- cardview-v7/build.gradle | 4 ++-- design/build.gradle | 4 ++-- gson-adapter/build.gradle | 4 ++-- proteus-core/build.gradle | 4 ++-- recyclerview-v7/build.gradle | 4 ++-- support-v4/build.gradle | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index cc7af16c..b5a633ef 100644 --- a/build.gradle +++ b/build.gradle @@ -43,8 +43,8 @@ allprojects { ext { groupName = 'com.github.flipkart-incubator.proteus' - versionName = '5.0.0-rc13' - versionCode = 500013 + versionName = '5.0.0-snapshot' + versionCode = 500014 compileSdkVersion = 28 minSdkVersion = 14 targetSdkVersion = 28 diff --git a/cardview-v7/build.gradle b/cardview-v7/build.gradle index ad2e12a8..4c4c8898 100644 --- a/cardview-v7/build.gradle +++ b/cardview-v7/build.gradle @@ -30,8 +30,8 @@ android { defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 1 - versionName "1.0" + versionCode rootProject.ext.versionCode + versionName rootProject.ext.versionName testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" diff --git a/design/build.gradle b/design/build.gradle index bf2e7dad..b2e6c0f4 100644 --- a/design/build.gradle +++ b/design/build.gradle @@ -30,8 +30,8 @@ android { defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 1 - versionName "1.0" + versionCode rootProject.ext.versionCode + versionName rootProject.ext.versionName testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" diff --git a/gson-adapter/build.gradle b/gson-adapter/build.gradle index 4a29bc96..57dfe9a5 100644 --- a/gson-adapter/build.gradle +++ b/gson-adapter/build.gradle @@ -30,8 +30,8 @@ android { defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 1 - versionName "1.0" + versionCode rootProject.ext.versionCode + versionName rootProject.ext.versionName testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" diff --git a/proteus-core/build.gradle b/proteus-core/build.gradle index f425dcdd..e12bc692 100644 --- a/proteus-core/build.gradle +++ b/proteus-core/build.gradle @@ -29,8 +29,8 @@ android { defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 500000 - versionName "5.0.0" + versionCode rootProject.ext.versionCode + versionName rootProject.ext.versionName } lintOptions { diff --git a/recyclerview-v7/build.gradle b/recyclerview-v7/build.gradle index 210095d7..69d91b42 100644 --- a/recyclerview-v7/build.gradle +++ b/recyclerview-v7/build.gradle @@ -30,8 +30,8 @@ android { defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 1 - versionName "1.0" + versionCode rootProject.ext.versionCode + versionName rootProject.ext.versionName testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" diff --git a/support-v4/build.gradle b/support-v4/build.gradle index f5b5d3fc..7466b08a 100644 --- a/support-v4/build.gradle +++ b/support-v4/build.gradle @@ -30,8 +30,8 @@ android { defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 1 - versionName "1.0" + versionCode rootProject.ext.versionCode + versionName rootProject.ext.versionName testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" From e033778b714ca8253db2bdc23863bcde38b78fb2 Mon Sep 17 00:00:00 2001 From: Aditya Sharat Date: Sun, 13 Jan 2019 00:04:03 +0000 Subject: [PATCH 02/19] fix the version name and version code of demo --- demo/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demo/build.gradle b/demo/build.gradle index 598fb9f9..e7231f66 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -27,8 +27,8 @@ android { applicationId "com.flipkart.android.proteus.demo" minSdkVersion 19 targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 500000 - versionName "5.0.0" + versionCode rootProject.ext.versionCode + versionName rootProject.ext.versionName } buildTypes { From c77bae2dfda260de084840c838a4cac253233095 Mon Sep 17 00:00:00 2001 From: Aditya Sharat Date: Sun, 13 Jan 2019 00:04:24 +0000 Subject: [PATCH 03/19] bump min sdk version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index b5a633ef..30a9e3de 100644 --- a/build.gradle +++ b/build.gradle @@ -46,7 +46,7 @@ ext { versionName = '5.0.0-snapshot' versionCode = 500014 compileSdkVersion = 28 - minSdkVersion = 14 + minSdkVersion = 19 targetSdkVersion = 28 buildToolsVersion = '28.0.3' supportLibraryVersion = '28.0.0' From 2ef8d7af5dc160dec1025a0337dbc603aea70169 Mon Sep 17 00:00:00 2001 From: Aditya Sharat Date: Sun, 13 Jan 2019 00:05:08 +0000 Subject: [PATCH 04/19] use project variable --- demo/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/build.gradle b/demo/build.gradle index e7231f66..0a23a6a9 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -25,7 +25,7 @@ android { defaultConfig { applicationId "com.flipkart.android.proteus.demo" - minSdkVersion 19 + minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode rootProject.ext.versionCode versionName rootProject.ext.versionName From 5ad17f7e9ca9553beadecd14d60f8e7aa48f622a Mon Sep 17 00:00:00 2001 From: Aditya Sharat Date: Sun, 13 Jan 2019 00:14:16 +0000 Subject: [PATCH 05/19] update copyright --- cardview-v7/build.gradle | 23 ++++++++----------- cardview-v7/src/main/AndroidManifest.xml | 23 ++++++++----------- .../proteus/support/v7/CardViewModule.java | 23 ++++++++----------- .../support/v7/widget/CardViewParser.java | 23 ++++++++----------- .../support/v7/widget/ProteusCardView.java | 23 ++++++++----------- cardview-v7/src/main/res/values/strings.xml | 23 ++++++++----------- 6 files changed, 60 insertions(+), 78 deletions(-) diff --git a/cardview-v7/build.gradle b/cardview-v7/build.gradle index 4c4c8898..174f8513 100644 --- a/cardview-v7/build.gradle +++ b/cardview-v7/build.gradle @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ apply plugin: 'com.android.library' diff --git a/cardview-v7/src/main/AndroidManifest.xml b/cardview-v7/src/main/AndroidManifest.xml index d3886ad5..2dc819ea 100644 --- a/cardview-v7/src/main/AndroidManifest.xml +++ b/cardview-v7/src/main/AndroidManifest.xml @@ -1,20 +1,17 @@ diff --git a/cardview-v7/src/main/java/com/flipkart/android/proteus/support/v7/CardViewModule.java b/cardview-v7/src/main/java/com/flipkart/android/proteus/support/v7/CardViewModule.java index d0f6610a..fae13020 100644 --- a/cardview-v7/src/main/java/com/flipkart/android/proteus/support/v7/CardViewModule.java +++ b/cardview-v7/src/main/java/com/flipkart/android/proteus/support/v7/CardViewModule.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.v7; diff --git a/cardview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/CardViewParser.java b/cardview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/CardViewParser.java index 13fa25c3..23c95ae5 100644 --- a/cardview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/CardViewParser.java +++ b/cardview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/CardViewParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.v7.widget; diff --git a/cardview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/ProteusCardView.java b/cardview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/ProteusCardView.java index e10e6920..f3d07367 100644 --- a/cardview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/ProteusCardView.java +++ b/cardview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/ProteusCardView.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.v7.widget; diff --git a/cardview-v7/src/main/res/values/strings.xml b/cardview-v7/src/main/res/values/strings.xml index 84de328d..3d011fcc 100644 --- a/cardview-v7/src/main/res/values/strings.xml +++ b/cardview-v7/src/main/res/values/strings.xml @@ -1,20 +1,17 @@ From fb29cc60536a131658176aa89d2efd7af8668c21 Mon Sep 17 00:00:00 2001 From: Aditya Sharat Date: Sun, 13 Jan 2019 00:14:49 +0000 Subject: [PATCH 06/19] update copyright --- demo/build.gradle | 23 ++++++++----------- demo/src/main/AndroidManifest.xml | 23 ++++++++----------- .../proteus/demo/CircleViewParser.java | 23 ++++++++----------- .../android/proteus/demo/DemoApplication.java | 23 ++++++++----------- .../android/proteus/demo/ProteusActivity.java | 23 ++++++++----------- .../android/proteus/demo/api/ProteusApi.java | 23 ++++++++----------- .../proteus/demo/api/ProteusManager.java | 23 ++++++++----------- .../demo/converter/GsonConverterFactory.java | 23 ++++++++----------- .../converter/GsonRequestBodyConverter.java | 23 ++++++++----------- .../converter/GsonResponseBodyConverter.java | 23 ++++++++----------- .../UrlEncodedGsonRequestBodyConverter.java | 23 ++++++++----------- .../proteus/demo/customviews/CircleView.java | 23 ++++++++----------- .../proteus/demo/utils/GlideAppModule.java | 23 ++++++++----------- .../proteus/demo/utils/ImageLoaderTarget.java | 23 ++++++++----------- demo/src/main/res/drawable/border.xml | 23 ++++++++----------- demo/src/main/res/layout/activity_main.xml | 23 ++++++++----------- demo/src/main/res/layout/activity_native.xml | 23 ++++++++----------- demo/src/main/res/layout/activity_proteus.xml | 23 ++++++++----------- demo/src/main/res/layout/content_main.xml | 23 ++++++++----------- .../res/layout/relative_layout_example.xml | 23 ++++++++----------- .../layout/simple_data_binding_example.xml | 23 ++++++++----------- demo/src/main/res/menu/main.xml | 23 ++++++++----------- demo/src/main/res/values-v21/styles.xml | 23 ++++++++----------- demo/src/main/res/values-w820dp/dimens.xml | 23 ++++++++----------- demo/src/main/res/values/bools.xml | 23 ++++++++----------- demo/src/main/res/values/colors.xml | 23 ++++++++----------- demo/src/main/res/values/dimens.xml | 23 ++++++++----------- demo/src/main/res/values/strings.xml | 23 ++++++++----------- demo/src/main/res/values/styles.xml | 23 ++++++++----------- 29 files changed, 290 insertions(+), 377 deletions(-) diff --git a/demo/build.gradle b/demo/build.gradle index 0a23a6a9..f90fe868 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ apply plugin: 'com.android.application' diff --git a/demo/src/main/AndroidManifest.xml b/demo/src/main/AndroidManifest.xml index 97c16de0..feaf9e42 100644 --- a/demo/src/main/AndroidManifest.xml +++ b/demo/src/main/AndroidManifest.xml @@ -1,20 +1,17 @@ diff --git a/demo/src/main/res/values-w820dp/dimens.xml b/demo/src/main/res/values-w820dp/dimens.xml index 8bbee3fc..05fa816a 100644 --- a/demo/src/main/res/values-w820dp/dimens.xml +++ b/demo/src/main/res/values-w820dp/dimens.xml @@ -1,20 +1,17 @@ diff --git a/demo/src/main/res/values/bools.xml b/demo/src/main/res/values/bools.xml index c4112d17..8e7f5e48 100644 --- a/demo/src/main/res/values/bools.xml +++ b/demo/src/main/res/values/bools.xml @@ -1,20 +1,17 @@ diff --git a/demo/src/main/res/values/colors.xml b/demo/src/main/res/values/colors.xml index eac24e1f..423762e7 100644 --- a/demo/src/main/res/values/colors.xml +++ b/demo/src/main/res/values/colors.xml @@ -1,20 +1,17 @@ diff --git a/demo/src/main/res/values/dimens.xml b/demo/src/main/res/values/dimens.xml index 77178484..0440a994 100644 --- a/demo/src/main/res/values/dimens.xml +++ b/demo/src/main/res/values/dimens.xml @@ -1,20 +1,17 @@ diff --git a/demo/src/main/res/values/strings.xml b/demo/src/main/res/values/strings.xml index a4eff55c..e12254fc 100644 --- a/demo/src/main/res/values/strings.xml +++ b/demo/src/main/res/values/strings.xml @@ -1,20 +1,17 @@ diff --git a/demo/src/main/res/values/styles.xml b/demo/src/main/res/values/styles.xml index c8b691a1..8531fbb7 100644 --- a/demo/src/main/res/values/styles.xml +++ b/demo/src/main/res/values/styles.xml @@ -1,20 +1,17 @@ From ef55994ea424ac28c488fb033d6589a1f01bcb6d Mon Sep 17 00:00:00 2001 From: Aditya Sharat Date: Sun, 13 Jan 2019 00:15:02 +0000 Subject: [PATCH 07/19] update copyright --- design/build.gradle | 23 ++++++++----------- design/src/main/AndroidManifest.xml | 23 ++++++++----------- .../proteus/support/design/DesignModule.java | 23 ++++++++----------- .../design/DesignModuleAttributeHelper.java | 23 ++++++++----------- .../design/widget/AppBarLayoutParser.java | 23 ++++++++----------- .../widget/BottomNavigationViewParser.java | 23 ++++++++----------- .../widget/CollapsingToolbarLayoutParser.java | 23 ++++++++----------- .../widget/CoordinatorLayoutParser.java | 23 ++++++++----------- .../widget/FloatingActionButtonParser.java | 23 ++++++++----------- .../design/widget/ProteusAppBarLayout.java | 23 ++++++++----------- .../widget/ProteusBottomNavigationView.java | 23 ++++++++----------- .../ProteusCollapsingToolbarLayout.java | 23 ++++++++----------- .../widget/ProteusCoordinatorLayout.java | 23 ++++++++----------- .../widget/ProteusFloatingActionButton.java | 23 ++++++++----------- .../design/widget/ProteusNavigationView.java | 23 ++++++++----------- .../design/widget/ProteusTabLayout.java | 23 ++++++++----------- .../widget/ProteusTextInputEditText.java | 23 ++++++++----------- .../design/widget/ProteusTextInputLayout.java | 23 ++++++++----------- 18 files changed, 180 insertions(+), 234 deletions(-) diff --git a/design/build.gradle b/design/build.gradle index b2e6c0f4..2f534f96 100644 --- a/design/build.gradle +++ b/design/build.gradle @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ apply plugin: 'com.android.library' diff --git a/design/src/main/AndroidManifest.xml b/design/src/main/AndroidManifest.xml index cc11530f..a104e313 100644 --- a/design/src/main/AndroidManifest.xml +++ b/design/src/main/AndroidManifest.xml @@ -1,20 +1,17 @@ diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/DesignModule.java b/design/src/main/java/com/flipkart/android/proteus/support/design/DesignModule.java index ff02cc44..77c6fc76 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/DesignModule.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/DesignModule.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.design; diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/DesignModuleAttributeHelper.java b/design/src/main/java/com/flipkart/android/proteus/support/design/DesignModuleAttributeHelper.java index 709d6884..1893fc4c 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/DesignModuleAttributeHelper.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/DesignModuleAttributeHelper.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.design; diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/AppBarLayoutParser.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/AppBarLayoutParser.java index 5b96e0da..3136f7a0 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/AppBarLayoutParser.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/AppBarLayoutParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.design.widget; diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/BottomNavigationViewParser.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/BottomNavigationViewParser.java index 40e8419e..e105cf9f 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/BottomNavigationViewParser.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/BottomNavigationViewParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.design.widget; diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/CollapsingToolbarLayoutParser.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/CollapsingToolbarLayoutParser.java index ff1a4e0d..b2ff9758 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/CollapsingToolbarLayoutParser.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/CollapsingToolbarLayoutParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.design.widget; diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/CoordinatorLayoutParser.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/CoordinatorLayoutParser.java index c3753487..7334268d 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/CoordinatorLayoutParser.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/CoordinatorLayoutParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.design.widget; diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/FloatingActionButtonParser.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/FloatingActionButtonParser.java index c1f790b4..3fa28550 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/FloatingActionButtonParser.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/FloatingActionButtonParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.design.widget; diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusAppBarLayout.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusAppBarLayout.java index d9d02e8d..df90ecc3 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusAppBarLayout.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusAppBarLayout.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.design.widget; diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusBottomNavigationView.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusBottomNavigationView.java index 685a6a2b..e0aa064c 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusBottomNavigationView.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusBottomNavigationView.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.design.widget; diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusCollapsingToolbarLayout.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusCollapsingToolbarLayout.java index 1f844e69..10540d13 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusCollapsingToolbarLayout.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusCollapsingToolbarLayout.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.design.widget; diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusCoordinatorLayout.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusCoordinatorLayout.java index a9620954..74cb05cf 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusCoordinatorLayout.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusCoordinatorLayout.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.design.widget; diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusFloatingActionButton.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusFloatingActionButton.java index 639f82e3..81690cc3 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusFloatingActionButton.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusFloatingActionButton.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.design.widget; diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusNavigationView.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusNavigationView.java index b754143f..29c7396a 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusNavigationView.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusNavigationView.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.design.widget; diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusTabLayout.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusTabLayout.java index 6571c048..e0472964 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusTabLayout.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusTabLayout.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.design.widget; diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusTextInputEditText.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusTextInputEditText.java index a1efb740..bff8a61d 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusTextInputEditText.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusTextInputEditText.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.design.widget; diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusTextInputLayout.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusTextInputLayout.java index e58d9a56..5fd41021 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusTextInputLayout.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusTextInputLayout.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.design.widget; From bd6e736c38f2fce7c61973302364ba4bc7357d13 Mon Sep 17 00:00:00 2001 From: Aditya Sharat Date: Sun, 13 Jan 2019 00:15:12 +0000 Subject: [PATCH 08/19] update copyright --- gson-adapter/build.gradle | 23 ++++++++----------- gson-adapter/src/main/AndroidManifest.xml | 23 ++++++++----------- .../proteus/gson/CustomValueTypeAdapter.java | 23 ++++++++----------- .../gson/CustomValueTypeAdapterCreator.java | 23 ++++++++----------- .../android/proteus/gson/DefaultModule.java | 23 ++++++++----------- .../gson/ProteusTypeAdapterFactory.java | 23 ++++++++----------- gson-adapter/src/main/res/values/strings.xml | 23 ++++++++----------- .../gson/ProteusTypeAdapterFactoryTest.java | 23 ++++++++----------- 8 files changed, 80 insertions(+), 104 deletions(-) diff --git a/gson-adapter/build.gradle b/gson-adapter/build.gradle index 57dfe9a5..d746c7bc 100644 --- a/gson-adapter/build.gradle +++ b/gson-adapter/build.gradle @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ apply plugin: 'com.android.library' diff --git a/gson-adapter/src/main/AndroidManifest.xml b/gson-adapter/src/main/AndroidManifest.xml index 0d044c42..4fd89c5a 100644 --- a/gson-adapter/src/main/AndroidManifest.xml +++ b/gson-adapter/src/main/AndroidManifest.xml @@ -1,20 +1,17 @@ diff --git a/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/CustomValueTypeAdapter.java b/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/CustomValueTypeAdapter.java index de379482..6afb9542 100644 --- a/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/CustomValueTypeAdapter.java +++ b/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/CustomValueTypeAdapter.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.gson; diff --git a/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/CustomValueTypeAdapterCreator.java b/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/CustomValueTypeAdapterCreator.java index 089f353e..e10a5f64 100644 --- a/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/CustomValueTypeAdapterCreator.java +++ b/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/CustomValueTypeAdapterCreator.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.gson; diff --git a/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/DefaultModule.java b/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/DefaultModule.java index 3c34c800..07cf9fb8 100644 --- a/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/DefaultModule.java +++ b/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/DefaultModule.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.gson; diff --git a/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/ProteusTypeAdapterFactory.java b/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/ProteusTypeAdapterFactory.java index adc5fb68..98cb68ae 100644 --- a/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/ProteusTypeAdapterFactory.java +++ b/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/ProteusTypeAdapterFactory.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.gson; diff --git a/gson-adapter/src/main/res/values/strings.xml b/gson-adapter/src/main/res/values/strings.xml index 4fb83898..a2c81592 100644 --- a/gson-adapter/src/main/res/values/strings.xml +++ b/gson-adapter/src/main/res/values/strings.xml @@ -1,20 +1,17 @@ diff --git a/gson-adapter/src/test/java/com/flipkart/android/proteus/gson/ProteusTypeAdapterFactoryTest.java b/gson-adapter/src/test/java/com/flipkart/android/proteus/gson/ProteusTypeAdapterFactoryTest.java index 3e35d1fa..7623290b 100644 --- a/gson-adapter/src/test/java/com/flipkart/android/proteus/gson/ProteusTypeAdapterFactoryTest.java +++ b/gson-adapter/src/test/java/com/flipkart/android/proteus/gson/ProteusTypeAdapterFactoryTest.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.gson; From 027bde8bf46947c7957543b4919a50c5b0182ff8 Mon Sep 17 00:00:00 2001 From: Aditya Sharat Date: Sun, 13 Jan 2019 00:15:22 +0000 Subject: [PATCH 09/19] update copyright --- build.gradle | 23 ++++++++++------------- gradle.properties | 23 ++++++++++------------- gradle/wrapper/gradle-wrapper.properties | 16 ++++++++++++++++ settings.gradle | 23 ++++++++++------------- 4 files changed, 46 insertions(+), 39 deletions(-) diff --git a/build.gradle b/build.gradle index 30a9e3de..57544034 100644 --- a/build.gradle +++ b/build.gradle @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ // Top-level build file where you can add configuration options common to all sub-projects/modules. diff --git a/gradle.properties b/gradle.properties index 240de0d5..ca09a229 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,20 +1,17 @@ # -# Apache License -# Version 2.0, January 2004 -# http://www.apache.org/licenses/LICENSE-2.0 +# Copyright 2019 Flipkart Internet Pvt. Ltd. # -# TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# Copyright (c) 2018 Flipkart Internet Pvt. Ltd. +# http://www.apache.org/licenses/LICENSE-2.0 # -# Licensed under the Apache License, Version 2.0 (the "License"); you may not use -# this file except in compliance with the License. You may obtain a copy of the -# License at http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software distributed -# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR -# CONDITIONS OF ANY KIND, either express or implied. See the License for the -# specific language governing permissions and limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. # # Project-wide Gradle settings. diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index eb864f3c..ed816330 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,3 +1,19 @@ +# +# Copyright 2019 Flipkart Internet Pvt. Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + #Tue Dec 18 18:50:19 GMT 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists diff --git a/settings.gradle b/settings.gradle index 8f19a9a1..885dbf2d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ include ':demo', ':proteus-core', ':gson-adapter', ':support-v4', ':recyclerview-v7', ':cardview-v7', ':design' \ No newline at end of file From dbce52e3bfa4bae74958f77203b022d73b89c1fd Mon Sep 17 00:00:00 2001 From: Aditya Sharat Date: Sun, 13 Jan 2019 00:15:30 +0000 Subject: [PATCH 10/19] update copyright --- proteus-core/AndroidManifest.xml | 23 ++++++++----------- proteus-core/build.gradle | 23 ++++++++----------- .../res/layout/layout_params_hack.xml | 23 ++++++++----------- proteus-core/res/values/values.xml | 23 ++++++++----------- proteus-core/src/main/AndroidManifest.xml | 23 ++++++++----------- .../android/proteus/BoundAttribute.java | 23 ++++++++----------- .../flipkart/android/proteus/DataContext.java | 23 ++++++++----------- .../flipkart/android/proteus/Function.java | 23 ++++++++----------- .../android/proteus/FunctionManager.java | 23 ++++++++----------- .../flipkart/android/proteus/IdGenerator.java | 23 ++++++++----------- .../android/proteus/LayoutManager.java | 23 ++++++++----------- .../com/flipkart/android/proteus/Proteus.java | 23 ++++++++----------- .../android/proteus/ProteusBuilder.java | 23 ++++++++----------- .../android/proteus/ProteusConstants.java | 23 ++++++++----------- .../android/proteus/ProteusContext.java | 23 ++++++++----------- .../proteus/ProteusContextWrapper.java | 23 ++++++++----------- .../proteus/ProteusLayoutInflater.java | 23 ++++++++----------- .../android/proteus/ProteusResources.java | 23 ++++++++----------- .../flipkart/android/proteus/ProteusView.java | 23 ++++++++----------- .../android/proteus/SimpleIdGenerator.java | 23 ++++++++----------- .../android/proteus/SimpleLayoutInflater.java | 23 ++++++++----------- .../android/proteus/StyleManager.java | 23 ++++++++----------- .../com/flipkart/android/proteus/Styles.java | 23 ++++++++----------- .../android/proteus/ViewTypeParser.java | 23 ++++++++----------- .../exceptions/ProteusInflateException.java | 23 ++++++++----------- .../managers/AdapterBasedViewManager.java | 23 ++++++++----------- .../proteus/managers/ViewGroupManager.java | 23 ++++++++----------- .../android/proteus/managers/ViewManager.java | 23 ++++++++----------- .../android/proteus/parser/IncludeParser.java | 23 ++++++++----------- .../android/proteus/parser/ParseHelper.java | 23 ++++++++----------- .../android/proteus/parser/ViewParser.java | 23 ++++++++----------- .../proteus/parser/custom/ButtonParser.java | 23 ++++++++----------- .../proteus/parser/custom/CheckBoxParser.java | 23 ++++++++----------- .../proteus/parser/custom/EditTextParser.java | 23 ++++++++----------- .../parser/custom/FrameLayoutParser.java | 23 ++++++++----------- .../custom/HorizontalProgressBarParser.java | 23 ++++++++----------- .../custom/HorizontalScrollViewParser.java | 23 ++++++++----------- .../parser/custom/ImageButtonParser.java | 23 ++++++++----------- .../parser/custom/ImageViewParser.java | 23 ++++++++----------- .../parser/custom/LinearLayoutParser.java | 23 ++++++++----------- .../parser/custom/ProgressBarParser.java | 23 ++++++++----------- .../parser/custom/RatingBarParser.java | 23 ++++++++----------- .../parser/custom/RelativeLayoutParser.java | 23 ++++++++----------- .../parser/custom/ScrollViewParser.java | 23 ++++++++----------- .../proteus/parser/custom/TextViewParser.java | 23 ++++++++----------- .../parser/custom/ViewGroupParser.java | 23 ++++++++----------- .../proteus/parser/custom/WebViewParser.java | 23 ++++++++----------- .../proteus/processor/AttributeProcessor.java | 23 ++++++++----------- .../processor/BooleanAttributeProcessor.java | 23 ++++++++----------- .../processor/ColorResourceProcessor.java | 23 ++++++++----------- .../DimensionAttributeProcessor.java | 23 ++++++++----------- .../processor/DrawableResourceProcessor.java | 23 ++++++++----------- .../proteus/processor/EventProcessor.java | 23 ++++++++----------- .../processor/GravityAttributeProcessor.java | 23 ++++++++----------- .../processor/NumberAttributeProcessor.java | 23 ++++++++----------- .../processor/StringAttributeProcessor.java | 23 ++++++++----------- .../TweenAnimationResourceProcessor.java | 23 ++++++++----------- .../proteus/toolbox/AnimationUtils.java | 23 ++++++++----------- .../android/proteus/toolbox/Attributes.java | 23 ++++++++----------- .../android/proteus/toolbox/BiMap.java | 23 ++++++++----------- .../android/proteus/toolbox/HashBiMap.java | 23 ++++++++----------- .../proteus/toolbox/LazilyParsedNumber.java | 23 ++++++++----------- .../proteus/toolbox/ManagerWrapper.java | 23 ++++++++----------- .../android/proteus/toolbox/Result.java | 23 ++++++++----------- .../proteus/toolbox/SimpleArrayIterator.java | 23 ++++++++----------- .../android/proteus/toolbox/Utils.java | 23 ++++++++----------- .../flipkart/android/proteus/value/Array.java | 23 ++++++++----------- .../proteus/value/AttributeResource.java | 23 ++++++++----------- .../android/proteus/value/Binding.java | 23 ++++++++----------- .../flipkart/android/proteus/value/Color.java | 23 ++++++++----------- .../android/proteus/value/Dimension.java | 23 ++++++++----------- .../android/proteus/value/DrawableValue.java | 23 ++++++++----------- .../android/proteus/value/Layout.java | 23 ++++++++----------- .../android/proteus/value/NestedBinding.java | 23 ++++++++----------- .../flipkart/android/proteus/value/Null.java | 23 ++++++++----------- .../android/proteus/value/ObjectValue.java | 23 ++++++++----------- .../android/proteus/value/Primitive.java | 23 ++++++++----------- .../android/proteus/value/Resource.java | 23 ++++++++----------- .../android/proteus/value/StyleResource.java | 23 ++++++++----------- .../flipkart/android/proteus/value/Value.java | 23 ++++++++----------- .../proteus/view/ProteusAndroidView.java | 23 ++++++++----------- .../view/ProteusAspectRatioFrameLayout.java | 23 ++++++++----------- .../android/proteus/view/ProteusButton.java | 23 ++++++++----------- .../android/proteus/view/ProteusCheckBox.java | 23 ++++++++----------- .../android/proteus/view/ProteusEditText.java | 23 ++++++++----------- .../proteus/view/ProteusFixedRatingBar.java | 23 ++++++++----------- .../view/ProteusHorizontalProgressBar.java | 23 ++++++++----------- .../view/ProteusHorizontalScrollView.java | 23 ++++++++----------- .../proteus/view/ProteusImageButton.java | 23 ++++++++----------- .../proteus/view/ProteusImageView.java | 23 ++++++++----------- .../proteus/view/ProteusLinearLayout.java | 23 ++++++++----------- .../proteus/view/ProteusProgressBar.java | 23 ++++++++----------- .../proteus/view/ProteusRelativeLayout.java | 23 ++++++++----------- .../proteus/view/ProteusScrollView.java | 23 ++++++++----------- .../android/proteus/view/ProteusTextView.java | 23 ++++++++----------- .../android/proteus/view/ProteusWebView.java | 23 ++++++++----------- .../view/custom/AspectRatioFrameLayout.java | 23 ++++++++----------- .../proteus/view/custom/FixedRatingBar.java | 23 ++++++++----------- .../view/custom/HorizontalProgressBar.java | 23 ++++++++----------- .../main/res/layout/layout_params_hack.xml | 23 ++++++++----------- .../src/test/java/android/graphics/Color.java | 23 ++++++++----------- .../src/test/java/android/util/LruCache.java | 23 ++++++++----------- .../test/java/android/util/TypedValue.java | 23 ++++++++----------- .../proteus/parser/ParseHelperTest.java | 23 ++++++++----------- .../DimensionAttributeProcessorTest.java | 23 ++++++++----------- .../GravityAttributeProcessorTest.java | 23 ++++++++----------- .../android/proteus/value/BindingTest.java | 23 ++++++++----------- .../android/proteus/value/DimensionTest.java | 23 ++++++++----------- .../android/proteus/value/ExpressionTest.java | 23 ++++++++----------- .../proteus/value/StyleResourceTest.java | 23 ++++++++----------- 110 files changed, 1100 insertions(+), 1430 deletions(-) diff --git a/proteus-core/AndroidManifest.xml b/proteus-core/AndroidManifest.xml index 791fcd8a..aa8f498c 100644 --- a/proteus-core/AndroidManifest.xml +++ b/proteus-core/AndroidManifest.xml @@ -1,21 +1,18 @@ \ No newline at end of file diff --git a/proteus-core/build.gradle b/proteus-core/build.gradle index e12bc692..3ab8db94 100644 --- a/proteus-core/build.gradle +++ b/proteus-core/build.gradle @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ apply plugin: 'com.android.library' apply plugin: 'com.github.dcendents.android-maven' diff --git a/proteus-core/res/layout/layout_params_hack.xml b/proteus-core/res/layout/layout_params_hack.xml index 4f69620c..30bed8de 100644 --- a/proteus-core/res/layout/layout_params_hack.xml +++ b/proteus-core/res/layout/layout_params_hack.xml @@ -1,22 +1,19 @@ diff --git a/proteus-core/src/main/AndroidManifest.xml b/proteus-core/src/main/AndroidManifest.xml index aa953528..0676f52e 100644 --- a/proteus-core/src/main/AndroidManifest.xml +++ b/proteus-core/src/main/AndroidManifest.xml @@ -1,20 +1,17 @@ diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/BoundAttribute.java b/proteus-core/src/main/java/com/flipkart/android/proteus/BoundAttribute.java index 4dca4f31..a3903dc9 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/BoundAttribute.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/BoundAttribute.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/DataContext.java b/proteus-core/src/main/java/com/flipkart/android/proteus/DataContext.java index 9d2e3e85..d3568bf9 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/DataContext.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/DataContext.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/Function.java b/proteus-core/src/main/java/com/flipkart/android/proteus/Function.java index 754c7be7..bd8d6549 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/Function.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/Function.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/FunctionManager.java b/proteus-core/src/main/java/com/flipkart/android/proteus/FunctionManager.java index 82b0f1b5..5e9a226a 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/FunctionManager.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/FunctionManager.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/IdGenerator.java b/proteus-core/src/main/java/com/flipkart/android/proteus/IdGenerator.java index cca9cb33..c735c0c4 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/IdGenerator.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/IdGenerator.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/LayoutManager.java b/proteus-core/src/main/java/com/flipkart/android/proteus/LayoutManager.java index f837d801..7317c870 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/LayoutManager.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/LayoutManager.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/Proteus.java b/proteus-core/src/main/java/com/flipkart/android/proteus/Proteus.java index d0f3a1e0..b53a2cab 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/Proteus.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/Proteus.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusBuilder.java b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusBuilder.java index 1a40f357..c3bd42de 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusBuilder.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusBuilder.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusConstants.java b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusConstants.java index 83221bf4..e165ebb2 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusConstants.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusConstants.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusContext.java b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusContext.java index 66fba4a7..f32828c6 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusContext.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusContext.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusContextWrapper.java b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusContextWrapper.java index ee2d0a62..b75e94be 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusContextWrapper.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusContextWrapper.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusLayoutInflater.java b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusLayoutInflater.java index 261e67db..0532014e 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusLayoutInflater.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusLayoutInflater.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusResources.java b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusResources.java index 84ec80d8..1978a931 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusResources.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusResources.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusView.java b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusView.java index 841897ed..825bc106 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusView.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusView.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/SimpleIdGenerator.java b/proteus-core/src/main/java/com/flipkart/android/proteus/SimpleIdGenerator.java index bf8cf90d..12a4b72e 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/SimpleIdGenerator.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/SimpleIdGenerator.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/SimpleLayoutInflater.java b/proteus-core/src/main/java/com/flipkart/android/proteus/SimpleLayoutInflater.java index f12ff974..ae172e16 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/SimpleLayoutInflater.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/SimpleLayoutInflater.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/StyleManager.java b/proteus-core/src/main/java/com/flipkart/android/proteus/StyleManager.java index c86475fe..99fb27b9 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/StyleManager.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/StyleManager.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/Styles.java b/proteus-core/src/main/java/com/flipkart/android/proteus/Styles.java index 930724ee..507127c8 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/Styles.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/Styles.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/ViewTypeParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/ViewTypeParser.java index 83770396..9b2bb187 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/ViewTypeParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/ViewTypeParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/exceptions/ProteusInflateException.java b/proteus-core/src/main/java/com/flipkart/android/proteus/exceptions/ProteusInflateException.java index f0015145..0f71b329 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/exceptions/ProteusInflateException.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/exceptions/ProteusInflateException.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.exceptions; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/managers/AdapterBasedViewManager.java b/proteus-core/src/main/java/com/flipkart/android/proteus/managers/AdapterBasedViewManager.java index 4ac2984c..0fc0de5a 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/managers/AdapterBasedViewManager.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/managers/AdapterBasedViewManager.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.managers; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/managers/ViewGroupManager.java b/proteus-core/src/main/java/com/flipkart/android/proteus/managers/ViewGroupManager.java index c32262e9..9f608c4c 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/managers/ViewGroupManager.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/managers/ViewGroupManager.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.managers; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/managers/ViewManager.java b/proteus-core/src/main/java/com/flipkart/android/proteus/managers/ViewManager.java index 0078d388..abaa8520 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/managers/ViewManager.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/managers/ViewManager.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.managers; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/IncludeParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/IncludeParser.java index 07843d75..e5bebcb7 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/IncludeParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/IncludeParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.parser; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/ParseHelper.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/ParseHelper.java index 127eef26..1d3dfbbb 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/ParseHelper.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/ParseHelper.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.parser; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/ViewParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/ViewParser.java index e43036ed..eba5d43b 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/ViewParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/ViewParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.parser; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ButtonParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ButtonParser.java index 0ed84669..3d740628 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ButtonParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ButtonParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.parser.custom; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/CheckBoxParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/CheckBoxParser.java index 3b2e53c4..3260679a 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/CheckBoxParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/CheckBoxParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.parser.custom; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/EditTextParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/EditTextParser.java index 9c44d17c..2ffbf24f 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/EditTextParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/EditTextParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.parser.custom; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/FrameLayoutParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/FrameLayoutParser.java index f9516636..fdd5537b 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/FrameLayoutParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/FrameLayoutParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.parser.custom; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/HorizontalProgressBarParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/HorizontalProgressBarParser.java index f5f4cd70..e1d0a86c 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/HorizontalProgressBarParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/HorizontalProgressBarParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.parser.custom; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/HorizontalScrollViewParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/HorizontalScrollViewParser.java index 40bcf159..fa279508 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/HorizontalScrollViewParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/HorizontalScrollViewParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.parser.custom; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ImageButtonParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ImageButtonParser.java index 2f8db60e..b73fe471 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ImageButtonParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ImageButtonParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.parser.custom; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ImageViewParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ImageViewParser.java index 6b7f639a..5b6cf54a 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ImageViewParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ImageViewParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.parser.custom; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/LinearLayoutParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/LinearLayoutParser.java index 9224284d..33045980 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/LinearLayoutParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/LinearLayoutParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.parser.custom; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ProgressBarParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ProgressBarParser.java index 160448ab..6686a5b1 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ProgressBarParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ProgressBarParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.parser.custom; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/RatingBarParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/RatingBarParser.java index 3d09576a..684cf623 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/RatingBarParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/RatingBarParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.parser.custom; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/RelativeLayoutParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/RelativeLayoutParser.java index 9de83806..d1c57205 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/RelativeLayoutParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/RelativeLayoutParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.parser.custom; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ScrollViewParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ScrollViewParser.java index be5cce37..a5205c65 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ScrollViewParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ScrollViewParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.parser.custom; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/TextViewParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/TextViewParser.java index 44fabbae..316e70c7 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/TextViewParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/TextViewParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.parser.custom; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ViewGroupParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ViewGroupParser.java index ce00a6ff..87f856f5 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ViewGroupParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ViewGroupParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.parser.custom; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/WebViewParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/WebViewParser.java index 820b4488..c88e2ec9 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/WebViewParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/WebViewParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.parser.custom; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/AttributeProcessor.java b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/AttributeProcessor.java index 36a0d820..dc313e54 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/AttributeProcessor.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/AttributeProcessor.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.processor; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/BooleanAttributeProcessor.java b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/BooleanAttributeProcessor.java index 45bfefbb..2182215f 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/BooleanAttributeProcessor.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/BooleanAttributeProcessor.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.processor; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/ColorResourceProcessor.java b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/ColorResourceProcessor.java index 07182355..c9fcede3 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/ColorResourceProcessor.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/ColorResourceProcessor.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.processor; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/DimensionAttributeProcessor.java b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/DimensionAttributeProcessor.java index 5efc1aa7..64f2fc85 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/DimensionAttributeProcessor.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/DimensionAttributeProcessor.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.processor; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/DrawableResourceProcessor.java b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/DrawableResourceProcessor.java index 47d67eca..192674f1 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/DrawableResourceProcessor.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/DrawableResourceProcessor.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.processor; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/EventProcessor.java b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/EventProcessor.java index b9b0f694..01a28530 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/EventProcessor.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/EventProcessor.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.processor; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/GravityAttributeProcessor.java b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/GravityAttributeProcessor.java index ca00c5b4..3d9f8782 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/GravityAttributeProcessor.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/GravityAttributeProcessor.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.processor; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/NumberAttributeProcessor.java b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/NumberAttributeProcessor.java index 18fdba50..78064692 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/NumberAttributeProcessor.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/NumberAttributeProcessor.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.processor; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/StringAttributeProcessor.java b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/StringAttributeProcessor.java index 57606545..a08d86f7 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/StringAttributeProcessor.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/StringAttributeProcessor.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.processor; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/TweenAnimationResourceProcessor.java b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/TweenAnimationResourceProcessor.java index da7db65c..f467b96b 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/TweenAnimationResourceProcessor.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/TweenAnimationResourceProcessor.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.processor; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/AnimationUtils.java b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/AnimationUtils.java index 283dd842..4cdab4b8 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/AnimationUtils.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/AnimationUtils.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.toolbox; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Attributes.java b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Attributes.java index 652a2491..aebadc7a 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Attributes.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Attributes.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.toolbox; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/BiMap.java b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/BiMap.java index 0588bfff..151fb669 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/BiMap.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/BiMap.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.toolbox; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/HashBiMap.java b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/HashBiMap.java index 83164723..b66decdc 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/HashBiMap.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/HashBiMap.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.toolbox; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/LazilyParsedNumber.java b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/LazilyParsedNumber.java index 4f6e5379..0df893ea 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/LazilyParsedNumber.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/LazilyParsedNumber.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.toolbox; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/ManagerWrapper.java b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/ManagerWrapper.java index b84bf62f..897adefc 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/ManagerWrapper.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/ManagerWrapper.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.toolbox; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Result.java b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Result.java index ee78148e..d2aaa429 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Result.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Result.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.toolbox; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/SimpleArrayIterator.java b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/SimpleArrayIterator.java index 87f9c02d..c8d0682f 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/SimpleArrayIterator.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/SimpleArrayIterator.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.toolbox; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Utils.java b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Utils.java index db673e16..aee51d3c 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Utils.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Utils.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.toolbox; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Array.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Array.java index f209c837..fa617fee 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Array.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Array.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.value; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/AttributeResource.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/AttributeResource.java index 27cb835a..1dfcbcab 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/AttributeResource.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/AttributeResource.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.value; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Binding.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Binding.java index 31f957a3..0210701a 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Binding.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Binding.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.value; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Color.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Color.java index f59a23f6..1fc49c64 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Color.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Color.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.value; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Dimension.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Dimension.java index 8c7f7d13..16b610da 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Dimension.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Dimension.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.value; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/DrawableValue.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/DrawableValue.java index 8618ee9e..d9eafa4a 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/DrawableValue.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/DrawableValue.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.value; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Layout.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Layout.java index 178d55b9..4e194eba 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Layout.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Layout.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.value; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/NestedBinding.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/NestedBinding.java index e39b477b..3c133c88 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/NestedBinding.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/NestedBinding.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.value; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Null.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Null.java index 0678deac..2f38089b 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Null.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Null.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.value; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/ObjectValue.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/ObjectValue.java index 1904d7cc..281eb1d0 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/ObjectValue.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/ObjectValue.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.value; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Primitive.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Primitive.java index 4e673b32..879f6ac9 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Primitive.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Primitive.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.value; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Resource.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Resource.java index 2dabec71..bf903dbb 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Resource.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Resource.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.value; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/StyleResource.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/StyleResource.java index e38e63bc..b9447b43 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/StyleResource.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/StyleResource.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.value; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Value.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Value.java index b903623e..4e3a6bf0 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Value.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Value.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.value; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusAndroidView.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusAndroidView.java index 7a4ae325..7d651acd 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusAndroidView.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusAndroidView.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.view; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusAspectRatioFrameLayout.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusAspectRatioFrameLayout.java index b42d00b5..71d0610e 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusAspectRatioFrameLayout.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusAspectRatioFrameLayout.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.view; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusButton.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusButton.java index 5ef6dd77..26e50626 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusButton.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusButton.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.view; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusCheckBox.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusCheckBox.java index 168b21ba..ac680a2f 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusCheckBox.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusCheckBox.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.view; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusEditText.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusEditText.java index e26cf79e..6e2c904e 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusEditText.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusEditText.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.view; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusFixedRatingBar.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusFixedRatingBar.java index 57a5a8dd..6a08cc35 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusFixedRatingBar.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusFixedRatingBar.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.view; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusHorizontalProgressBar.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusHorizontalProgressBar.java index bda38fce..e8483d9c 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusHorizontalProgressBar.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusHorizontalProgressBar.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.view; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusHorizontalScrollView.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusHorizontalScrollView.java index d0f07bbf..809e8de0 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusHorizontalScrollView.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusHorizontalScrollView.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.view; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusImageButton.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusImageButton.java index b20e1ef3..adb53345 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusImageButton.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusImageButton.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.view; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusImageView.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusImageView.java index e6e9efab..5fbac206 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusImageView.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusImageView.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.view; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusLinearLayout.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusLinearLayout.java index c8ad6088..60c3d192 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusLinearLayout.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusLinearLayout.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.view; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusProgressBar.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusProgressBar.java index 8562fb04..5879a99e 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusProgressBar.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusProgressBar.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.view; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusRelativeLayout.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusRelativeLayout.java index f5d307d8..6fbd5b36 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusRelativeLayout.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusRelativeLayout.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.view; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusScrollView.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusScrollView.java index a67b019c..e01062bc 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusScrollView.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusScrollView.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.view; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusTextView.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusTextView.java index fd40a370..63c86e54 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusTextView.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusTextView.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.view; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusWebView.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusWebView.java index 545d95bd..d89f42fc 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusWebView.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusWebView.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.view; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/AspectRatioFrameLayout.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/AspectRatioFrameLayout.java index 36d3b231..3c779aa9 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/AspectRatioFrameLayout.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/AspectRatioFrameLayout.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.view.custom; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/FixedRatingBar.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/FixedRatingBar.java index da45e58d..287193b9 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/FixedRatingBar.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/FixedRatingBar.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.view.custom; diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/HorizontalProgressBar.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/HorizontalProgressBar.java index cde6a8ab..54590dbb 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/HorizontalProgressBar.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/HorizontalProgressBar.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.view.custom; diff --git a/proteus-core/src/main/res/layout/layout_params_hack.xml b/proteus-core/src/main/res/layout/layout_params_hack.xml index 18a17e78..0f797169 100644 --- a/proteus-core/src/main/res/layout/layout_params_hack.xml +++ b/proteus-core/src/main/res/layout/layout_params_hack.xml @@ -1,22 +1,19 @@ Date: Sun, 13 Jan 2019 00:15:37 +0000 Subject: [PATCH 11/19] update copyright --- recyclerview-v7/build.gradle | 23 ++++++++----------- recyclerview-v7/src/main/AndroidManifest.xml | 23 ++++++++----------- .../support/v7/RecyclerViewModule.java | 23 ++++++++----------- .../adapter/ProteusRecyclerViewAdapter.java | 23 ++++++++----------- .../support/v7/adapter/ProteusViewHolder.java | 23 ++++++++----------- .../adapter/RecyclerViewAdapterFactory.java | 23 ++++++++----------- .../support/v7/adapter/SimpleListAdapter.java | 23 ++++++++----------- .../layoutmanager/LayoutManagerBuilder.java | 23 ++++++++----------- .../layoutmanager/LayoutManagerFactory.java | 23 ++++++++----------- .../ProteusLinearLayoutManager.java | 23 ++++++++----------- .../v7/widget/ProteusRecyclerView.java | 23 ++++++++----------- .../support/v7/widget/RecyclerViewParser.java | 23 ++++++++----------- 12 files changed, 120 insertions(+), 156 deletions(-) diff --git a/recyclerview-v7/build.gradle b/recyclerview-v7/build.gradle index 69d91b42..2dd99feb 100644 --- a/recyclerview-v7/build.gradle +++ b/recyclerview-v7/build.gradle @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ apply plugin: 'com.android.library' diff --git a/recyclerview-v7/src/main/AndroidManifest.xml b/recyclerview-v7/src/main/AndroidManifest.xml index d7848de2..5d8307c6 100644 --- a/recyclerview-v7/src/main/AndroidManifest.xml +++ b/recyclerview-v7/src/main/AndroidManifest.xml @@ -1,20 +1,17 @@ diff --git a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/RecyclerViewModule.java b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/RecyclerViewModule.java index e8dc4ca7..f12480ab 100644 --- a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/RecyclerViewModule.java +++ b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/RecyclerViewModule.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.v7; diff --git a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/ProteusRecyclerViewAdapter.java b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/ProteusRecyclerViewAdapter.java index ef25e54a..fb402f24 100644 --- a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/ProteusRecyclerViewAdapter.java +++ b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/ProteusRecyclerViewAdapter.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.v7.adapter; diff --git a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/ProteusViewHolder.java b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/ProteusViewHolder.java index 6ed6bd81..61d4e11e 100644 --- a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/ProteusViewHolder.java +++ b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/ProteusViewHolder.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.v7.adapter; diff --git a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/RecyclerViewAdapterFactory.java b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/RecyclerViewAdapterFactory.java index e47c254e..97d150fc 100644 --- a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/RecyclerViewAdapterFactory.java +++ b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/RecyclerViewAdapterFactory.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.v7.adapter; diff --git a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/SimpleListAdapter.java b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/SimpleListAdapter.java index 05f0fa5d..59de54d6 100644 --- a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/SimpleListAdapter.java +++ b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/SimpleListAdapter.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.v7.adapter; diff --git a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/layoutmanager/LayoutManagerBuilder.java b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/layoutmanager/LayoutManagerBuilder.java index c928735f..8e74cc11 100644 --- a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/layoutmanager/LayoutManagerBuilder.java +++ b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/layoutmanager/LayoutManagerBuilder.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.v7.layoutmanager; diff --git a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/layoutmanager/LayoutManagerFactory.java b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/layoutmanager/LayoutManagerFactory.java index dacae030..3ceb8fda 100644 --- a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/layoutmanager/LayoutManagerFactory.java +++ b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/layoutmanager/LayoutManagerFactory.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.v7.layoutmanager; diff --git a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/layoutmanager/ProteusLinearLayoutManager.java b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/layoutmanager/ProteusLinearLayoutManager.java index dd3809dc..d7bf86db 100644 --- a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/layoutmanager/ProteusLinearLayoutManager.java +++ b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/layoutmanager/ProteusLinearLayoutManager.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.v7.layoutmanager; diff --git a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/ProteusRecyclerView.java b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/ProteusRecyclerView.java index 4c122833..6da72509 100644 --- a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/ProteusRecyclerView.java +++ b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/ProteusRecyclerView.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.v7.widget; diff --git a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/RecyclerViewParser.java b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/RecyclerViewParser.java index 07787b5f..c7c4c8b3 100644 --- a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/RecyclerViewParser.java +++ b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/RecyclerViewParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.v7.widget; From d1e8d4216ffbc8c423a752a66eafe2a2721e14ef Mon Sep 17 00:00:00 2001 From: Aditya Sharat Date: Sun, 13 Jan 2019 00:15:46 +0000 Subject: [PATCH 12/19] update copyright --- support-v4/build.gradle | 23 ++++++++----------- support-v4/src/main/AndroidManifest.xml | 23 ++++++++----------- .../proteus/support/v4/SupportV4Module.java | 23 ++++++++----------- .../support/v4/view/ProteusViewPager.java | 23 ++++++++----------- .../support/v4/view/ViewPagerParser.java | 23 ++++++++----------- support-v4/src/main/res/values/strings.xml | 23 ++++++++----------- 6 files changed, 60 insertions(+), 78 deletions(-) diff --git a/support-v4/build.gradle b/support-v4/build.gradle index 7466b08a..aa49b1dc 100644 --- a/support-v4/build.gradle +++ b/support-v4/build.gradle @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ apply plugin: 'com.android.library' diff --git a/support-v4/src/main/AndroidManifest.xml b/support-v4/src/main/AndroidManifest.xml index 291ec039..ab57e268 100644 --- a/support-v4/src/main/AndroidManifest.xml +++ b/support-v4/src/main/AndroidManifest.xml @@ -1,20 +1,17 @@ diff --git a/support-v4/src/main/java/com/flipkart/android/proteus/support/v4/SupportV4Module.java b/support-v4/src/main/java/com/flipkart/android/proteus/support/v4/SupportV4Module.java index cb89c127..c501c205 100644 --- a/support-v4/src/main/java/com/flipkart/android/proteus/support/v4/SupportV4Module.java +++ b/support-v4/src/main/java/com/flipkart/android/proteus/support/v4/SupportV4Module.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.v4; diff --git a/support-v4/src/main/java/com/flipkart/android/proteus/support/v4/view/ProteusViewPager.java b/support-v4/src/main/java/com/flipkart/android/proteus/support/v4/view/ProteusViewPager.java index 5bde7d8f..b98a0782 100644 --- a/support-v4/src/main/java/com/flipkart/android/proteus/support/v4/view/ProteusViewPager.java +++ b/support-v4/src/main/java/com/flipkart/android/proteus/support/v4/view/ProteusViewPager.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.v4.view; diff --git a/support-v4/src/main/java/com/flipkart/android/proteus/support/v4/view/ViewPagerParser.java b/support-v4/src/main/java/com/flipkart/android/proteus/support/v4/view/ViewPagerParser.java index 2446a0ad..44c6a3e3 100644 --- a/support-v4/src/main/java/com/flipkart/android/proteus/support/v4/view/ViewPagerParser.java +++ b/support-v4/src/main/java/com/flipkart/android/proteus/support/v4/view/ViewPagerParser.java @@ -1,20 +1,17 @@ /* - * Apache License - * Version 2.0, January 2004 - * http://www.apache.org/licenses/LICENSE-2.0 + * Copyright 2019 Flipkart Internet Pvt. Ltd. * - * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Copyright (c) 2018 Flipkart Internet Pvt. Ltd. + * http://www.apache.org/licenses/LICENSE-2.0 * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use - * this file except in compliance with the License. You may obtain a copy of the - * License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.flipkart.android.proteus.support.v4.view; diff --git a/support-v4/src/main/res/values/strings.xml b/support-v4/src/main/res/values/strings.xml index e6c7d538..daafb835 100644 --- a/support-v4/src/main/res/values/strings.xml +++ b/support-v4/src/main/res/values/strings.xml @@ -1,20 +1,17 @@ From ac6eebf5b187ea4924a9842c0e47d783db5d3858 Mon Sep 17 00:00:00 2001 From: Aditya Sharat Date: Sun, 13 Jan 2019 00:46:56 +0000 Subject: [PATCH 13/19] reformat code --- .../proteus/support/v7/CardViewModule.java | 18 +- .../support/v7/widget/CardViewParser.java | 240 +++++++++--------- .../support/v7/widget/ProteusCardView.java | 42 +-- 3 files changed, 150 insertions(+), 150 deletions(-) diff --git a/cardview-v7/src/main/java/com/flipkart/android/proteus/support/v7/CardViewModule.java b/cardview-v7/src/main/java/com/flipkart/android/proteus/support/v7/CardViewModule.java index fae13020..e8d605fc 100644 --- a/cardview-v7/src/main/java/com/flipkart/android/proteus/support/v7/CardViewModule.java +++ b/cardview-v7/src/main/java/com/flipkart/android/proteus/support/v7/CardViewModule.java @@ -27,15 +27,15 @@ public class CardViewModule implements ProteusBuilder.Module { - private CardViewModule() { - } + private CardViewModule() { + } - public static CardViewModule create() { - return new CardViewModule(); - } + public static CardViewModule create() { + return new CardViewModule(); + } - @Override - public void registerWith(ProteusBuilder builder) { - builder.register(new CardViewParser()); - } + @Override + public void registerWith(ProteusBuilder builder) { + builder.register(new CardViewParser()); + } } diff --git a/cardview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/CardViewParser.java b/cardview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/CardViewParser.java index 23c95ae5..33c7f209 100644 --- a/cardview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/CardViewParser.java +++ b/cardview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/CardViewParser.java @@ -39,124 +39,124 @@ public class CardViewParser extends ViewTypeParser { - @NonNull - @Override - public String getType() { - return "CardView"; - } - - @Nullable - @Override - public String getParentType() { - return "FrameLayout"; - } - - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { - return new ProteusCardView(context); - } - - @Override - protected void addAttributeProcessors() { - - addAttributeProcessor("cardBackgroundColor", new ColorResourceProcessor() { - @Override - public void setColor(T view, int color) { - view.setCardBackgroundColor(color); - } - - @Override - public void setColor(T view, ColorStateList colors) { - view.setCardBackgroundColor(colors); - } - }); - - addAttributeProcessor("cardCornerRadius", new DimensionAttributeProcessor() { - @Override - public void setDimension(T view, float dimension) { - view.setRadius(dimension); - } - }); - - addAttributeProcessor("cardElevation", new DimensionAttributeProcessor() { - @Override - public void setDimension(T view, float dimension) { - view.setCardElevation(dimension); - } - }); - - addAttributeProcessor("cardMaxElevation", new DimensionAttributeProcessor() { - @Override - public void setDimension(T view, float dimension) { - view.setMaxCardElevation(dimension); - } - }); - - addAttributeProcessor("cardPreventCornerOverlap", new BooleanAttributeProcessor() { - @Override - public void setBoolean(T view, boolean value) { - view.setPreventCornerOverlap(value); - } - }); - - addAttributeProcessor("cardUseCompatPadding", new BooleanAttributeProcessor() { - @Override - public void setBoolean(T view, boolean value) { - view.setUseCompatPadding(value); - } - }); - - addAttributeProcessor("contentPadding", new DimensionAttributeProcessor() { - @Override - public void setDimension(T view, float dimension) { - view.setContentPadding((int) dimension, (int) dimension, (int) dimension, (int) dimension); - } - }); - - addAttributeProcessor("contentPaddingBottom", new DimensionAttributeProcessor() { - @Override - public void setDimension(T view, float dimension) { - int t = view.getContentPaddingTop(); - int r = view.getContentPaddingRight(); - int l = view.getContentPaddingLeft(); - - view.setContentPadding(l, t, r, (int) dimension); - } - }); - - addAttributeProcessor("contentPaddingLeft", new DimensionAttributeProcessor() { - @Override - public void setDimension(T view, float dimension) { - int t = view.getContentPaddingTop(); - int r = view.getContentPaddingRight(); - int b = view.getContentPaddingBottom(); - - view.setContentPadding((int) dimension, t, r, b); - } - }); - - addAttributeProcessor("contentPaddingRight", new DimensionAttributeProcessor() { - @Override - public void setDimension(T view, float dimension) { - int t = view.getContentPaddingTop(); - int b = view.getContentPaddingBottom(); - int l = view.getContentPaddingLeft(); - - view.setContentPadding(l, t, (int) dimension, b); - } - }); - - addAttributeProcessor("contentPaddingTop", new DimensionAttributeProcessor() { - @Override - public void setDimension(T view, float dimension) { - int r = view.getContentPaddingRight(); - int b = view.getContentPaddingBottom(); - int l = view.getContentPaddingLeft(); - - view.setContentPadding(l, (int) dimension, r, b); - } - }); - - } + @NonNull + @Override + public String getType() { + return "CardView"; + } + + @Nullable + @Override + public String getParentType() { + return "FrameLayout"; + } + + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { + return new ProteusCardView(context); + } + + @Override + protected void addAttributeProcessors() { + + addAttributeProcessor("cardBackgroundColor", new ColorResourceProcessor() { + @Override + public void setColor(T view, int color) { + view.setCardBackgroundColor(color); + } + + @Override + public void setColor(T view, ColorStateList colors) { + view.setCardBackgroundColor(colors); + } + }); + + addAttributeProcessor("cardCornerRadius", new DimensionAttributeProcessor() { + @Override + public void setDimension(T view, float dimension) { + view.setRadius(dimension); + } + }); + + addAttributeProcessor("cardElevation", new DimensionAttributeProcessor() { + @Override + public void setDimension(T view, float dimension) { + view.setCardElevation(dimension); + } + }); + + addAttributeProcessor("cardMaxElevation", new DimensionAttributeProcessor() { + @Override + public void setDimension(T view, float dimension) { + view.setMaxCardElevation(dimension); + } + }); + + addAttributeProcessor("cardPreventCornerOverlap", new BooleanAttributeProcessor() { + @Override + public void setBoolean(T view, boolean value) { + view.setPreventCornerOverlap(value); + } + }); + + addAttributeProcessor("cardUseCompatPadding", new BooleanAttributeProcessor() { + @Override + public void setBoolean(T view, boolean value) { + view.setUseCompatPadding(value); + } + }); + + addAttributeProcessor("contentPadding", new DimensionAttributeProcessor() { + @Override + public void setDimension(T view, float dimension) { + view.setContentPadding((int) dimension, (int) dimension, (int) dimension, (int) dimension); + } + }); + + addAttributeProcessor("contentPaddingBottom", new DimensionAttributeProcessor() { + @Override + public void setDimension(T view, float dimension) { + int t = view.getContentPaddingTop(); + int r = view.getContentPaddingRight(); + int l = view.getContentPaddingLeft(); + + view.setContentPadding(l, t, r, (int) dimension); + } + }); + + addAttributeProcessor("contentPaddingLeft", new DimensionAttributeProcessor() { + @Override + public void setDimension(T view, float dimension) { + int t = view.getContentPaddingTop(); + int r = view.getContentPaddingRight(); + int b = view.getContentPaddingBottom(); + + view.setContentPadding((int) dimension, t, r, b); + } + }); + + addAttributeProcessor("contentPaddingRight", new DimensionAttributeProcessor() { + @Override + public void setDimension(T view, float dimension) { + int t = view.getContentPaddingTop(); + int b = view.getContentPaddingBottom(); + int l = view.getContentPaddingLeft(); + + view.setContentPadding(l, t, (int) dimension, b); + } + }); + + addAttributeProcessor("contentPaddingTop", new DimensionAttributeProcessor() { + @Override + public void setDimension(T view, float dimension) { + int r = view.getContentPaddingRight(); + int b = view.getContentPaddingBottom(); + int l = view.getContentPaddingLeft(); + + view.setContentPadding(l, (int) dimension, r, b); + } + }); + + } } diff --git a/cardview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/ProteusCardView.java b/cardview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/ProteusCardView.java index f3d07367..34babc9b 100644 --- a/cardview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/ProteusCardView.java +++ b/cardview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/ProteusCardView.java @@ -31,25 +31,25 @@ public class ProteusCardView extends CardView implements ProteusView { - private Manager manager; - - public ProteusCardView(ProteusContext context) { - super(context); - } - - @Override - public Manager getViewManager() { - return manager; - } - - @Override - public void setViewManager(@NonNull Manager manager) { - this.manager = manager; - } - - @NonNull - @Override - public View getAsView() { - return this; - } + private Manager manager; + + public ProteusCardView(ProteusContext context) { + super(context); + } + + @Override + public Manager getViewManager() { + return manager; + } + + @Override + public void setViewManager(@NonNull Manager manager) { + this.manager = manager; + } + + @NonNull + @Override + public View getAsView() { + return this; + } } From 34a7b339405f49eb10a341639b96ab11ded46243 Mon Sep 17 00:00:00 2001 From: Aditya Sharat Date: Sun, 13 Jan 2019 00:47:13 +0000 Subject: [PATCH 14/19] reformat code --- .../proteus/demo/CircleViewParser.java | 48 +-- .../android/proteus/demo/DemoApplication.java | 60 ++-- .../android/proteus/demo/ProteusActivity.java | 290 +++++++++--------- .../android/proteus/demo/api/ProteusApi.java | 16 +- .../proteus/demo/api/ProteusManager.java | 198 ++++++------ .../demo/converter/GsonConverterFactory.java | 66 ++-- .../converter/GsonRequestBodyConverter.java | 52 ++-- .../converter/GsonResponseBodyConverter.java | 46 +-- .../UrlEncodedGsonRequestBodyConverter.java | 40 +-- .../proteus/demo/customviews/CircleView.java | 132 ++++---- .../proteus/demo/utils/ImageLoaderTarget.java | 18 +- 11 files changed, 483 insertions(+), 483 deletions(-) diff --git a/demo/src/main/java/com/flipkart/android/proteus/demo/CircleViewParser.java b/demo/src/main/java/com/flipkart/android/proteus/demo/CircleViewParser.java index 30bf33f5..70dd5d80 100644 --- a/demo/src/main/java/com/flipkart/android/proteus/demo/CircleViewParser.java +++ b/demo/src/main/java/com/flipkart/android/proteus/demo/CircleViewParser.java @@ -36,33 +36,33 @@ public class CircleViewParser extends ViewTypeParser { - @NonNull - @Override - public String getType() { - return "CircleView"; - } + @NonNull + @Override + public String getType() { + return "CircleView"; + } - @Nullable - @Override - public String getParentType() { - return "View"; - } + @Nullable + @Override + public String getParentType() { + return "View"; + } - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { - return new CircleView(context); - } + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { + return new CircleView(context); + } - @Override - protected void addAttributeProcessors() { + @Override + protected void addAttributeProcessors() { - addAttributeProcessor("color", new StringAttributeProcessor() { - @Override - public void setString(CircleView view, String value) { - view.setColor(value); - } - }); - } + addAttributeProcessor("color", new StringAttributeProcessor() { + @Override + public void setString(CircleView view, String value) { + view.setColor(value); + } + }); + } } diff --git a/demo/src/main/java/com/flipkart/android/proteus/demo/DemoApplication.java b/demo/src/main/java/com/flipkart/android/proteus/demo/DemoApplication.java index 010550eb..8b71212f 100644 --- a/demo/src/main/java/com/flipkart/android/proteus/demo/DemoApplication.java +++ b/demo/src/main/java/com/flipkart/android/proteus/demo/DemoApplication.java @@ -28,42 +28,42 @@ public class DemoApplication extends Application { - private static final String BASE_URL = "http://10.0.2.2:8080/data/"; + private static final String BASE_URL = "http://10.0.2.2:8080/data/"; - private Gson gson; - private Retrofit retrofit; - private ProteusManager proteusManager; + private Gson gson; + private Retrofit retrofit; + private ProteusManager proteusManager; - @Override - public void onCreate() { - super.onCreate(); + @Override + public void onCreate() { + super.onCreate(); - // register the proteus type adapter to deserialize proteus resources - ProteusTypeAdapterFactory adapter = new ProteusTypeAdapterFactory(this); - gson = new GsonBuilder() - .registerTypeAdapterFactory(adapter) - .create(); + // register the proteus type adapter to deserialize proteus resources + ProteusTypeAdapterFactory adapter = new ProteusTypeAdapterFactory(this); + gson = new GsonBuilder() + .registerTypeAdapterFactory(adapter) + .create(); - // add gson to retrofit to allow deserializing proteus resources when fetched via retrofit - retrofit = new Retrofit.Builder() - .baseUrl(BASE_URL) - .addConverterFactory(GsonConverterFactory.create(getGson())) - .build(); + // add gson to retrofit to allow deserializing proteus resources when fetched via retrofit + retrofit = new Retrofit.Builder() + .baseUrl(BASE_URL) + .addConverterFactory(GsonConverterFactory.create(getGson())) + .build(); - // ProteusManager is a reference implementation to fetch and - // update all proteus resources from a remote server - proteusManager = new ProteusManager(getRetrofit()); - } + // ProteusManager is a reference implementation to fetch and + // update all proteus resources from a remote server + proteusManager = new ProteusManager(getRetrofit()); + } - public Gson getGson() { - return gson; - } + public Gson getGson() { + return gson; + } - public Retrofit getRetrofit() { - return retrofit; - } + public Retrofit getRetrofit() { + return retrofit; + } - public ProteusManager getProteusManager() { - return proteusManager; - } + public ProteusManager getProteusManager() { + return proteusManager; + } } diff --git a/demo/src/main/java/com/flipkart/android/proteus/demo/ProteusActivity.java b/demo/src/main/java/com/flipkart/android/proteus/demo/ProteusActivity.java index 5a565f61..52af3401 100644 --- a/demo/src/main/java/com/flipkart/android/proteus/demo/ProteusActivity.java +++ b/demo/src/main/java/com/flipkart/android/proteus/demo/ProteusActivity.java @@ -50,174 +50,174 @@ public class ProteusActivity extends AppCompatActivity implements ProteusManager.Listener { - private ProteusManager proteusManager; - private ProteusLayoutInflater layoutInflater; + private ProteusManager proteusManager; + private ProteusLayoutInflater layoutInflater; - ObjectValue data; - Layout layout; - Styles styles; - Map layouts; + ObjectValue data; + Layout layout; + Styles styles; + Map layouts; - private StyleManager styleManager = new StyleManager() { - - @Nullable - @Override - protected Styles getStyles() { - return styles; - } - }; - - private LayoutManager layoutManager = new LayoutManager() { - - @Nullable - @Override - protected Map getLayouts() { - return layouts; - } - }; - - /** - * Simple implementation of ImageLoader for loading images from url in background. - */ - private ProteusLayoutInflater.ImageLoader loader = new ProteusLayoutInflater.ImageLoader() { - @Override - public void getBitmap(ProteusView view, String url, final DrawableValue.AsyncCallback callback) { - GlideApp.with(ProteusActivity.this) - .load(url) - .placeholder(R.drawable.placeholder) - .error(R.drawable.image_broken) - .into(new ImageLoaderTarget(callback)); - } - }; - - /** - * Implementation of Callback. This is where we get callbacks from proteus regarding - * errors and events. - */ - private ProteusLayoutInflater.Callback callback = new ProteusLayoutInflater.Callback() { - - @NonNull - @Override - public ProteusView onUnknownViewType(ProteusContext context, String type, Layout layout, ObjectValue data, int index) { - // TODO: instead return some implementation of an unknown view - throw new ProteusInflateException("Unknown view type '" + type + "' cannot be inflated"); - } - - @Override - public void onEvent(String event, Value value, ProteusView view) { - Log.i("ProteusEvent", value.toString()); - } - }; - - ProteusView view; - private ViewGroup container; + private StyleManager styleManager = new StyleManager() { + @Nullable @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setContentView(R.layout.activity_proteus); - - // set the toolbar - Toolbar toolbar = findViewById(R.id.toolbar); - setSupportActionBar(toolbar); - - // setBoolean refresh button click - FloatingActionButton fab = findViewById(R.id.fab); - fab.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - alert(); - } - }); - - container = findViewById(R.id.content_main); - - DemoApplication application = (DemoApplication) getApplication(); - proteusManager = application.getProteusManager(); - - ProteusContext context = proteusManager.getProteus().createContextBuilder(this) - .setLayoutManager(layoutManager) - .setCallback(callback) - .setImageLoader(loader) - .setStyleManager(styleManager) - .build(); - - layoutInflater = context.getInflater(); + protected Styles getStyles() { + return styles; } + }; - @Override - protected void onStart() { - super.onStart(); - proteusManager.addListener(this); - proteusManager.load(); - } + private LayoutManager layoutManager = new LayoutManager() { + @Nullable @Override - protected void onPause() { - super.onPause(); - proteusManager.removeListener(this); + protected Map getLayouts() { + return layouts; } + }; + /** + * Simple implementation of ImageLoader for loading images from url in background. + */ + private ProteusLayoutInflater.ImageLoader loader = new ProteusLayoutInflater.ImageLoader() { @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.main, menu); - return true; + public void getBitmap(ProteusView view, String url, final DrawableValue.AsyncCallback callback) { + GlideApp.with(ProteusActivity.this) + .load(url) + .placeholder(R.drawable.placeholder) + .error(R.drawable.image_broken) + .into(new ImageLoaderTarget(callback)); } + }; - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int id = item.getItemId(); - switch (id) { - case R.id.reload: - reload(); - return true; - } - return super.onOptionsItemSelected(item); - } + /** + * Implementation of Callback. This is where we get callbacks from proteus regarding + * errors and events. + */ + private ProteusLayoutInflater.Callback callback = new ProteusLayoutInflater.Callback() { + @NonNull @Override - public void onLoad() { - data = proteusManager.getData(); - layout = proteusManager.getRootLayout(); - layouts = proteusManager.getLayouts(); - styles = proteusManager.getStyles(); - render(); + public ProteusView onUnknownViewType(ProteusContext context, String type, Layout layout, ObjectValue data, int index) { + // TODO: instead return some implementation of an unknown view + throw new ProteusInflateException("Unknown view type '" + type + "' cannot be inflated"); } @Override - public void onError(@NonNull Exception e) { - Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); + public void onEvent(String event, Value value, ProteusView view) { + Log.i("ProteusEvent", value.toString()); } - - private void alert() { - ProteusView view = layoutInflater.inflate("AlertDialogLayout", data); - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setView(view.getAsView()) - .setPositiveButton(R.string.action_alert_ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - dialogInterface.dismiss(); - } - }) - .show(); + }; + + ProteusView view; + private ViewGroup container; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.activity_proteus); + + // set the toolbar + Toolbar toolbar = findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + // setBoolean refresh button click + FloatingActionButton fab = findViewById(R.id.fab); + fab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + alert(); + } + }); + + container = findViewById(R.id.content_main); + + DemoApplication application = (DemoApplication) getApplication(); + proteusManager = application.getProteusManager(); + + ProteusContext context = proteusManager.getProteus().createContextBuilder(this) + .setLayoutManager(layoutManager) + .setCallback(callback) + .setImageLoader(loader) + .setStyleManager(styleManager) + .build(); + + layoutInflater = context.getInflater(); + } + + @Override + protected void onStart() { + super.onStart(); + proteusManager.addListener(this); + proteusManager.load(); + } + + @Override + protected void onPause() { + super.onPause(); + proteusManager.removeListener(this); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.main, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + switch (id) { + case R.id.reload: + reload(); + return true; } + return super.onOptionsItemSelected(item); + } + + @Override + public void onLoad() { + data = proteusManager.getData(); + layout = proteusManager.getRootLayout(); + layouts = proteusManager.getLayouts(); + styles = proteusManager.getStyles(); + render(); + } + + @Override + public void onError(@NonNull Exception e) { + Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); + } + + private void alert() { + ProteusView view = layoutInflater.inflate("AlertDialogLayout", data); + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setView(view.getAsView()) + .setPositiveButton(R.string.action_alert_ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + dialogInterface.dismiss(); + } + }) + .show(); + } - void render() { + void render() { - // remove the current view - container.removeAllViews(); + // remove the current view + container.removeAllViews(); - // Inflate a new view using proteus - long start = System.currentTimeMillis(); - view = layoutInflater.inflate(layout, data, container, 0); - System.out.println("inflate time: " + (System.currentTimeMillis() - start)); + // Inflate a new view using proteus + long start = System.currentTimeMillis(); + view = layoutInflater.inflate(layout, data, container, 0); + System.out.println("inflate time: " + (System.currentTimeMillis() - start)); - // Add the inflated view to the container - container.addView(view.getAsView()); - } + // Add the inflated view to the container + container.addView(view.getAsView()); + } - void reload() { - proteusManager.update(); - } + void reload() { + proteusManager.update(); + } } diff --git a/demo/src/main/java/com/flipkart/android/proteus/demo/api/ProteusApi.java b/demo/src/main/java/com/flipkart/android/proteus/demo/api/ProteusApi.java index d2a54870..56c0b799 100644 --- a/demo/src/main/java/com/flipkart/android/proteus/demo/api/ProteusApi.java +++ b/demo/src/main/java/com/flipkart/android/proteus/demo/api/ProteusApi.java @@ -33,15 +33,15 @@ public interface ProteusApi { - @GET("user.json") - Call getUserData(); + @GET("user.json") + Call getUserData(); - @GET("styles.json") - Call getStyles(); + @GET("styles.json") + Call getStyles(); - @GET("layout.json") - Call getLayout(); + @GET("layout.json") + Call getLayout(); - @GET("layouts.json") - Call> getLayouts(); + @GET("layouts.json") + Call> getLayouts(); } \ No newline at end of file diff --git a/demo/src/main/java/com/flipkart/android/proteus/demo/api/ProteusManager.java b/demo/src/main/java/com/flipkart/android/proteus/demo/api/ProteusManager.java index 38d6577f..facb4026 100644 --- a/demo/src/main/java/com/flipkart/android/proteus/demo/api/ProteusManager.java +++ b/demo/src/main/java/com/flipkart/android/proteus/demo/api/ProteusManager.java @@ -41,119 +41,119 @@ public class ProteusManager { - private final ProteusApi api; - private final Proteus proteus; - - private ObjectValue data; - private Layout rootLayout; - private Map layouts; - private Styles styles; - - private Set listeners = new HashSet<>(); - - public ProteusManager(Retrofit retrofit) { - this.api = retrofit.create(ProteusApi.class); - proteus = new ProteusBuilder() - .register(SupportV4Module.create()) - .register(RecyclerViewModule.create()) - .register(CardViewModule.create()) - .register(DesignModule.create()) - .register(new CircleViewParser()) - .build(); - - ProteusTypeAdapterFactory.PROTEUS_INSTANCE_HOLDER.setProteus(proteus); + private final ProteusApi api; + private final Proteus proteus; + + private ObjectValue data; + private Layout rootLayout; + private Map layouts; + private Styles styles; + + private Set listeners = new HashSet<>(); + + public ProteusManager(Retrofit retrofit) { + this.api = retrofit.create(ProteusApi.class); + proteus = new ProteusBuilder() + .register(SupportV4Module.create()) + .register(RecyclerViewModule.create()) + .register(CardViewModule.create()) + .register(DesignModule.create()) + .register(new CircleViewParser()) + .build(); + + ProteusTypeAdapterFactory.PROTEUS_INSTANCE_HOLDER.setProteus(proteus); + } + + public void load() { + new DataLoaderTask(this).execute(); + } + + public void update() { + new DataLoaderTask(this).execute(); + } + + public Proteus getProteus() { + return proteus; + } + + public ObjectValue getData() { + return data; + } + + public Layout getRootLayout() { + return rootLayout; + } + + public Map getLayouts() { + return layouts; + } + + public Styles getStyles() { + return styles; + } + + public void addListener(@NonNull Listener listener) { + listeners.add(listener); + } + + public void removeListener(@NonNull Listener listener) { + listeners.remove(listener); + } + + private void broadcast(@Nullable Exception e) { + if (e == null) { + notifySuccess(); + } else { + notifyError(e); } + } - public void load() { - new DataLoaderTask(this).execute(); + private void notifySuccess() { + for (Listener listener : listeners) { + listener.onLoad(); } + } - public void update() { - new DataLoaderTask(this).execute(); + private void notifyError(@NonNull Exception e) { + for (Listener listener : listeners) { + listener.onError(e); } + } - public Proteus getProteus() { - return proteus; - } - - public ObjectValue getData() { - return data; - } - - public Layout getRootLayout() { - return rootLayout; - } + private static class DataLoaderTask extends AsyncTask { - public Map getLayouts() { - return layouts; - } + private final ProteusManager manager; - public Styles getStyles() { - return styles; + DataLoaderTask(ProteusManager manager) { + this.manager = manager; } - public void addListener(@NonNull Listener listener) { - listeners.add(listener); + @Override + protected Exception doInBackground(Void... params) { + try { + ProteusApi api = manager.api; + manager.data = api.getUserData().execute().body(); + manager.rootLayout = api.getLayout().execute().body(); + manager.layouts = api.getLayouts().execute().body(); + manager.styles = api.getStyles().execute().body(); + } catch (Exception e) { + Log.e(getClass().getSimpleName(), "ERROR: " + e.getMessage()); + return e; + } + return null; } - public void removeListener(@NonNull Listener listener) { - listeners.remove(listener); + @Override + protected void onPostExecute(Exception e) { + super.onPostExecute(e); + manager.broadcast(e); } + } - private void broadcast(@Nullable Exception e) { - if (e == null) { - notifySuccess(); - } else { - notifyError(e); - } - } + public interface Listener { - private void notifySuccess() { - for (Listener listener : listeners) { - listener.onLoad(); - } - } + void onLoad(); - private void notifyError(@NonNull Exception e) { - for (Listener listener : listeners) { - listener.onError(e); - } - } - - private static class DataLoaderTask extends AsyncTask { - - private final ProteusManager manager; - - DataLoaderTask(ProteusManager manager) { - this.manager = manager; - } - - @Override - protected Exception doInBackground(Void... params) { - try { - ProteusApi api = manager.api; - manager.data = api.getUserData().execute().body(); - manager.rootLayout = api.getLayout().execute().body(); - manager.layouts = api.getLayouts().execute().body(); - manager.styles = api.getStyles().execute().body(); - } catch (Exception e) { - Log.e(getClass().getSimpleName(), "ERROR: " + e.getMessage()); - return e; - } - return null; - } - - @Override - protected void onPostExecute(Exception e) { - super.onPostExecute(e); - manager.broadcast(e); - } - } - - public interface Listener { - - void onLoad(); - - void onError(@NonNull Exception e); - } + void onError(@NonNull Exception e); + } } diff --git a/demo/src/main/java/com/flipkart/android/proteus/demo/converter/GsonConverterFactory.java b/demo/src/main/java/com/flipkart/android/proteus/demo/converter/GsonConverterFactory.java index e1127409..05623907 100644 --- a/demo/src/main/java/com/flipkart/android/proteus/demo/converter/GsonConverterFactory.java +++ b/demo/src/main/java/com/flipkart/android/proteus/demo/converter/GsonConverterFactory.java @@ -33,44 +33,44 @@ public final class GsonConverterFactory extends Converter.Factory { - private final Gson gson; + private final Gson gson; - private GsonConverterFactory(Gson gson) { - this.gson = gson; - } - - public static GsonConverterFactory create(Gson gson) { - return new GsonConverterFactory(gson); - } + private GsonConverterFactory(Gson gson) { + this.gson = gson; + } - @Override - public Converter responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) { - return new GsonResponseBodyConverter<>(gson, type); - } + public static GsonConverterFactory create(Gson gson) { + return new GsonConverterFactory(gson); + } - @Override - public Converter requestBodyConverter(Type type, Annotation[] parameterAnnotations, - Annotation[] methodAnnotations, Retrofit retrofit) { - Converter result = null; - for (Annotation annotation : methodAnnotations) { - if (annotation instanceof URLEncoded) { - result = new UrlEncodedGsonRequestBodyConverter<>(gson, type); - } - } + @Override + public Converter responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) { + return new GsonResponseBodyConverter<>(gson, type); + } - if (null == result) { - result = new GsonRequestBodyConverter<>(gson, type); - } - - return result; + @Override + public Converter requestBodyConverter(Type type, Annotation[] parameterAnnotations, + Annotation[] methodAnnotations, Retrofit retrofit) { + Converter result = null; + for (Annotation annotation : methodAnnotations) { + if (annotation instanceof URLEncoded) { + result = new UrlEncodedGsonRequestBodyConverter<>(gson, type); + } } - /** - * URL Encode the JSON String object before sending it over the wire. - */ - @Documented - @Target(METHOD) - @Retention(RUNTIME) - public @interface URLEncoded { + if (null == result) { + result = new GsonRequestBodyConverter<>(gson, type); } + + return result; + } + + /** + * URL Encode the JSON String object before sending it over the wire. + */ + @Documented + @Target(METHOD) + @Retention(RUNTIME) + public @interface URLEncoded { + } } diff --git a/demo/src/main/java/com/flipkart/android/proteus/demo/converter/GsonRequestBodyConverter.java b/demo/src/main/java/com/flipkart/android/proteus/demo/converter/GsonRequestBodyConverter.java index 0f9feb3c..dbc84bc1 100644 --- a/demo/src/main/java/com/flipkart/android/proteus/demo/converter/GsonRequestBodyConverter.java +++ b/demo/src/main/java/com/flipkart/android/proteus/demo/converter/GsonRequestBodyConverter.java @@ -32,36 +32,36 @@ import retrofit2.Converter; final class GsonRequestBodyConverter implements Converter { - private static final MediaType MEDIA_TYPE = MediaType.parse("application/json; charset=UTF-8"); - private static final Charset UTF_8 = Charset.forName("UTF-8"); + private static final MediaType MEDIA_TYPE = MediaType.parse("application/json; charset=UTF-8"); + private static final Charset UTF_8 = Charset.forName("UTF-8"); - private final Gson gson; - private final Type type; - private TypeAdapter typeAdapter; + private final Gson gson; + private final Type type; + private TypeAdapter typeAdapter; - GsonRequestBodyConverter(Gson gson, Type type) { - this.gson = gson; - this.type = type; - } + GsonRequestBodyConverter(Gson gson, Type type) { + this.gson = gson; + this.type = type; + } - private TypeAdapter getAdapter() { - if (null == typeAdapter) { - //noinspection unchecked - typeAdapter = (TypeAdapter) gson.getAdapter(TypeToken.get(type)); - } - return typeAdapter; + private TypeAdapter getAdapter() { + if (null == typeAdapter) { + //noinspection unchecked + typeAdapter = (TypeAdapter) gson.getAdapter(TypeToken.get(type)); } + return typeAdapter; + } - @Override - public RequestBody convert(T value) throws IOException { - TypeAdapter adapter = getAdapter(); - Buffer buffer = new Buffer(); - Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8); - JsonWriter jsonWriter = gson.newJsonWriter(writer); - jsonWriter.setSerializeNulls(true); - adapter.write(jsonWriter, value); - jsonWriter.close(); - return RequestBody.create(MEDIA_TYPE, buffer.readByteString()); - } + @Override + public RequestBody convert(T value) throws IOException { + TypeAdapter adapter = getAdapter(); + Buffer buffer = new Buffer(); + Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8); + JsonWriter jsonWriter = gson.newJsonWriter(writer); + jsonWriter.setSerializeNulls(true); + adapter.write(jsonWriter, value); + jsonWriter.close(); + return RequestBody.create(MEDIA_TYPE, buffer.readByteString()); + } } \ No newline at end of file diff --git a/demo/src/main/java/com/flipkart/android/proteus/demo/converter/GsonResponseBodyConverter.java b/demo/src/main/java/com/flipkart/android/proteus/demo/converter/GsonResponseBodyConverter.java index df3fd5f5..d2327360 100644 --- a/demo/src/main/java/com/flipkart/android/proteus/demo/converter/GsonResponseBodyConverter.java +++ b/demo/src/main/java/com/flipkart/android/proteus/demo/converter/GsonResponseBodyConverter.java @@ -27,32 +27,32 @@ import retrofit2.Converter; final class GsonResponseBodyConverter implements Converter { - private final Gson gson; - private final Type type; - private TypeAdapter typeAdapter; + private final Gson gson; + private final Type type; + private TypeAdapter typeAdapter; - GsonResponseBodyConverter(Gson gson, Type type) { - this.gson = gson; - this.type = type; - } + GsonResponseBodyConverter(Gson gson, Type type) { + this.gson = gson; + this.type = type; + } - private TypeAdapter getAdapter() { - if (null == typeAdapter) { - //noinspection unchecked - typeAdapter = (TypeAdapter) gson.getAdapter(TypeToken.get(type)); - } - return typeAdapter; + private TypeAdapter getAdapter() { + if (null == typeAdapter) { + //noinspection unchecked + typeAdapter = (TypeAdapter) gson.getAdapter(TypeToken.get(type)); } + return typeAdapter; + } - @Override - public T convert(ResponseBody value) throws IOException { - TypeAdapter adapter = getAdapter(); - JsonReader jsonReader = gson.newJsonReader(value.charStream()); - jsonReader.setLenient(true); - try { - return adapter.read(jsonReader); - } finally { - value.close(); - } + @Override + public T convert(ResponseBody value) throws IOException { + TypeAdapter adapter = getAdapter(); + JsonReader jsonReader = gson.newJsonReader(value.charStream()); + jsonReader.setLenient(true); + try { + return adapter.read(jsonReader); + } finally { + value.close(); } + } } \ No newline at end of file diff --git a/demo/src/main/java/com/flipkart/android/proteus/demo/converter/UrlEncodedGsonRequestBodyConverter.java b/demo/src/main/java/com/flipkart/android/proteus/demo/converter/UrlEncodedGsonRequestBodyConverter.java index 9d6f3b31..df8fd667 100755 --- a/demo/src/main/java/com/flipkart/android/proteus/demo/converter/UrlEncodedGsonRequestBodyConverter.java +++ b/demo/src/main/java/com/flipkart/android/proteus/demo/converter/UrlEncodedGsonRequestBodyConverter.java @@ -32,24 +32,24 @@ import retrofit2.Converter; class UrlEncodedGsonRequestBodyConverter implements Converter { - private static final MediaType MEDIA_TYPE = MediaType.parse("application/json; charset=UTF-8"); - private final Gson gson; - private final Type type; - - - UrlEncodedGsonRequestBodyConverter(Gson gson, Type type) { - this.gson = gson; - this.type = type; - } - - @Override - public RequestBody convert(T value) throws IOException { - //noinspection unchecked - TypeAdapter adapter = (TypeAdapter) gson.getAdapter(TypeToken.get(type)); - Writer writer = new StringWriter(); - JsonWriter jsonWriter = gson.newJsonWriter(writer); - adapter.write(jsonWriter, value); - jsonWriter.close(); - return RequestBody.create(MEDIA_TYPE, URLEncoder.encode(writer.toString(), "UTF-8").getBytes()); - } + private static final MediaType MEDIA_TYPE = MediaType.parse("application/json; charset=UTF-8"); + private final Gson gson; + private final Type type; + + + UrlEncodedGsonRequestBodyConverter(Gson gson, Type type) { + this.gson = gson; + this.type = type; + } + + @Override + public RequestBody convert(T value) throws IOException { + //noinspection unchecked + TypeAdapter adapter = (TypeAdapter) gson.getAdapter(TypeToken.get(type)); + Writer writer = new StringWriter(); + JsonWriter jsonWriter = gson.newJsonWriter(writer); + adapter.write(jsonWriter, value); + jsonWriter.close(); + return RequestBody.create(MEDIA_TYPE, URLEncoder.encode(writer.toString(), "UTF-8").getBytes()); + } } diff --git a/demo/src/main/java/com/flipkart/android/proteus/demo/customviews/CircleView.java b/demo/src/main/java/com/flipkart/android/proteus/demo/customviews/CircleView.java index 03c4fd6f..f128b00f 100644 --- a/demo/src/main/java/com/flipkart/android/proteus/demo/customviews/CircleView.java +++ b/demo/src/main/java/com/flipkart/android/proteus/demo/customviews/CircleView.java @@ -37,73 +37,73 @@ public class CircleView extends View implements ProteusView { - Manager viewManager; - private String HEX_COLOR = "#45ba8a"; - private Paint drawPaint; - float radius; - - public CircleView(Context context) { - super(context); - init(); + Manager viewManager; + private String HEX_COLOR = "#45ba8a"; + private Paint drawPaint; + float radius; + + public CircleView(Context context) { + super(context); + init(); + } + + public CircleView(final Context context, final AttributeSet attrs) { + super(context, attrs); + init(); + } + + public void setColor(String HEX_COLOR) { + this.HEX_COLOR = HEX_COLOR; + } + + @Override + public Manager getViewManager() { + return viewManager; + } + + @Override + public void setViewManager(@NonNull Manager viewManager) { + this.viewManager = viewManager; + } + + private void init() { + drawPaint = new Paint(); + drawPaint.setColor(Color.parseColor(HEX_COLOR)); + drawPaint.setAntiAlias(true); + setOnMeasureCallback(); + } + + @Override + protected void onDraw(final Canvas canvas) { + super.onDraw(canvas); + canvas.drawCircle(radius, radius, radius, drawPaint); + } + + private void setOnMeasureCallback() { + ViewTreeObserver vto = getViewTreeObserver(); + vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + removeOnGlobalLayoutListener(this); + radius = getMeasuredWidth() / 2; + } + }); + } + + @TargetApi(Build.VERSION_CODES.JELLY_BEAN) + void removeOnGlobalLayoutListener(ViewTreeObserver.OnGlobalLayoutListener listener) { + if (Build.VERSION.SDK_INT < 16) { + //noinspection deprecation + getViewTreeObserver().removeGlobalOnLayoutListener(listener); + } else { + getViewTreeObserver().removeOnGlobalLayoutListener(listener); } + } - public CircleView(final Context context, final AttributeSet attrs) { - super(context, attrs); - init(); - } - - public void setColor(String HEX_COLOR) { - this.HEX_COLOR = HEX_COLOR; - } - - @Override - public Manager getViewManager() { - return viewManager; - } - - @Override - public void setViewManager(@NonNull Manager viewManager) { - this.viewManager = viewManager; - } - - private void init() { - drawPaint = new Paint(); - drawPaint.setColor(Color.parseColor(HEX_COLOR)); - drawPaint.setAntiAlias(true); - setOnMeasureCallback(); - } - - @Override - protected void onDraw(final Canvas canvas) { - super.onDraw(canvas); - canvas.drawCircle(radius, radius, radius, drawPaint); - } - - private void setOnMeasureCallback() { - ViewTreeObserver vto = getViewTreeObserver(); - vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - removeOnGlobalLayoutListener(this); - radius = getMeasuredWidth() / 2; - } - }); - } - - @TargetApi(Build.VERSION_CODES.JELLY_BEAN) - void removeOnGlobalLayoutListener(ViewTreeObserver.OnGlobalLayoutListener listener) { - if (Build.VERSION.SDK_INT < 16) { - //noinspection deprecation - getViewTreeObserver().removeGlobalOnLayoutListener(listener); - } else { - getViewTreeObserver().removeOnGlobalLayoutListener(listener); - } - } - - @NonNull - @Override - public View getAsView() { - return this; - } + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/demo/src/main/java/com/flipkart/android/proteus/demo/utils/ImageLoaderTarget.java b/demo/src/main/java/com/flipkart/android/proteus/demo/utils/ImageLoaderTarget.java index 7ae6c8b0..329ecda6 100644 --- a/demo/src/main/java/com/flipkart/android/proteus/demo/utils/ImageLoaderTarget.java +++ b/demo/src/main/java/com/flipkart/android/proteus/demo/utils/ImageLoaderTarget.java @@ -26,15 +26,15 @@ public class ImageLoaderTarget extends SimpleTarget { - @NonNull - private final DrawableValue.AsyncCallback callback; + @NonNull + private final DrawableValue.AsyncCallback callback; - public ImageLoaderTarget(@NonNull DrawableValue.AsyncCallback callback) { - this.callback = callback; - } + public ImageLoaderTarget(@NonNull DrawableValue.AsyncCallback callback) { + this.callback = callback; + } - @Override - public void onResourceReady(@NonNull Drawable resource, @Nullable Transition transition) { - callback.setDrawable(resource); - } + @Override + public void onResourceReady(@NonNull Drawable resource, @Nullable Transition transition) { + callback.setDrawable(resource); + } } From 551ee384e639bcd7b838daa343a1860b04a884df Mon Sep 17 00:00:00 2001 From: Aditya Sharat Date: Sun, 13 Jan 2019 00:47:28 +0000 Subject: [PATCH 15/19] reformat code --- .../proteus/support/design/DesignModule.java | 32 +- .../design/DesignModuleAttributeHelper.java | 350 +++++++++--------- .../design/widget/AppBarLayoutParser.java | 176 ++++----- .../widget/BottomNavigationViewParser.java | 192 +++++----- .../widget/CollapsingToolbarLayoutParser.java | 226 +++++------ .../widget/CoordinatorLayoutParser.java | 60 +-- .../widget/FloatingActionButtonParser.java | 160 ++++---- .../design/widget/ProteusAppBarLayout.java | 42 +-- .../widget/ProteusBottomNavigationView.java | 42 +-- .../ProteusCollapsingToolbarLayout.java | 42 +-- .../widget/ProteusCoordinatorLayout.java | 42 +-- .../widget/ProteusFloatingActionButton.java | 42 +-- .../design/widget/ProteusNavigationView.java | 42 +-- .../design/widget/ProteusTabLayout.java | 42 +-- .../widget/ProteusTextInputEditText.java | 42 +-- .../design/widget/ProteusTextInputLayout.java | 42 +-- 16 files changed, 787 insertions(+), 787 deletions(-) diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/DesignModule.java b/design/src/main/java/com/flipkart/android/proteus/support/design/DesignModule.java index 77c6fc76..efea6f32 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/DesignModule.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/DesignModule.java @@ -31,21 +31,21 @@ public class DesignModule implements ProteusBuilder.Module { - private DesignModule() { - } - - public static DesignModule create() { - return new DesignModule(); - } - - @Override - public void registerWith(ProteusBuilder builder) { - builder.register(new AppBarLayoutParser()); - builder.register(new BottomNavigationViewParser()); - builder.register(new CollapsingToolbarLayoutParser()); - builder.register(new CoordinatorLayoutParser()); - builder.register(new FloatingActionButtonParser()); - DesignModuleAttributeHelper.register(builder); - } + private DesignModule() { + } + + public static DesignModule create() { + return new DesignModule(); + } + + @Override + public void registerWith(ProteusBuilder builder) { + builder.register(new AppBarLayoutParser()); + builder.register(new BottomNavigationViewParser()); + builder.register(new CollapsingToolbarLayoutParser()); + builder.register(new CoordinatorLayoutParser()); + builder.register(new FloatingActionButtonParser()); + DesignModuleAttributeHelper.register(builder); + } } diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/DesignModuleAttributeHelper.java b/design/src/main/java/com/flipkart/android/proteus/support/design/DesignModuleAttributeHelper.java index 1893fc4c..f22719b0 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/DesignModuleAttributeHelper.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/DesignModuleAttributeHelper.java @@ -48,206 +48,206 @@ public class DesignModuleAttributeHelper { - public static void register(ProteusBuilder builder) { - - Map processors = new LinkedHashMap<>(4); - - processors.put("layout_scrollFlags", new StringAttributeProcessor() { - @Override - public void setString(V view, String value) { - AppBarLayoutParamsHelper.setLayoutScrollFlags(view, value); - } - }); - - processors.put("layout_collapseMode", new StringAttributeProcessor() { - @Override - public void setString(V view, String value) { - CollapsingToolbarLayoutParamsHelper.setCollapseMode(view, value); - } - }); - - processors.put("layout_parallaxMultiplier", new StringAttributeProcessor() { - @Override - public void setString(V view, String value) { - CollapsingToolbarLayoutParamsHelper.setParallaxMultiplier(view, value); - } - }); - - processors.put("layout_behavior", new StringAttributeProcessor() { - @Override - public void setString(V view, String value) { - CoordinatorLayoutParamsHelper.setLayoutBehavior(view, value); - } - }); - - processors.put(Attributes.View.LayoutGravity, new GravityAttributeProcessor() { - @Override - public void setGravity(V view, @Gravity int gravity) { - ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); - - if (layoutParams instanceof LinearLayout.LayoutParams) { - LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) layoutParams; - params.gravity = gravity; - view.setLayoutParams(layoutParams); - } else if (layoutParams instanceof FrameLayout.LayoutParams) { - FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) layoutParams; - params.gravity = gravity; - view.setLayoutParams(layoutParams); - } else if (layoutParams instanceof CoordinatorLayout.LayoutParams) { - CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) layoutParams; - params.gravity = gravity; - view.setLayoutParams(layoutParams); - } - } - }); - - builder.register("View", processors); + public static void register(ProteusBuilder builder) { + + Map processors = new LinkedHashMap<>(4); + + processors.put("layout_scrollFlags", new StringAttributeProcessor() { + @Override + public void setString(V view, String value) { + AppBarLayoutParamsHelper.setLayoutScrollFlags(view, value); + } + }); + + processors.put("layout_collapseMode", new StringAttributeProcessor() { + @Override + public void setString(V view, String value) { + CollapsingToolbarLayoutParamsHelper.setCollapseMode(view, value); + } + }); + + processors.put("layout_parallaxMultiplier", new StringAttributeProcessor() { + @Override + public void setString(V view, String value) { + CollapsingToolbarLayoutParamsHelper.setParallaxMultiplier(view, value); + } + }); + + processors.put("layout_behavior", new StringAttributeProcessor() { + @Override + public void setString(V view, String value) { + CoordinatorLayoutParamsHelper.setLayoutBehavior(view, value); + } + }); + + processors.put(Attributes.View.LayoutGravity, new GravityAttributeProcessor() { + @Override + public void setGravity(V view, @Gravity int gravity) { + ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); + + if (layoutParams instanceof LinearLayout.LayoutParams) { + LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) layoutParams; + params.gravity = gravity; + view.setLayoutParams(layoutParams); + } else if (layoutParams instanceof FrameLayout.LayoutParams) { + FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) layoutParams; + params.gravity = gravity; + view.setLayoutParams(layoutParams); + } else if (layoutParams instanceof CoordinatorLayout.LayoutParams) { + CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) layoutParams; + params.gravity = gravity; + view.setLayoutParams(layoutParams); + } + } + }); - } + builder.register("View", processors); - private static class AppBarLayoutParamsHelper { - private static final String SCROLL_FLAG_SCROLL = "scroll"; - private static final String SCROLL_FLAG_EXIT_UNTIL_COLLAPSED = "exitUntilCollapsed"; - private static final String SCROLL_FLAG_ENTER_ALWAYS = "enterAlways"; - private static final String SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED = "enterAlwaysCollapsed"; - private static final String SCROLL_FLAG_SNAP = "snap"; + } - private static final HashMap sScrollFlagMap = new HashMap<>(); + private static class AppBarLayoutParamsHelper { + private static final String SCROLL_FLAG_SCROLL = "scroll"; + private static final String SCROLL_FLAG_EXIT_UNTIL_COLLAPSED = "exitUntilCollapsed"; + private static final String SCROLL_FLAG_ENTER_ALWAYS = "enterAlways"; + private static final String SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED = "enterAlwaysCollapsed"; + private static final String SCROLL_FLAG_SNAP = "snap"; - private static boolean sInitialized = false; + private static final HashMap sScrollFlagMap = new HashMap<>(); - private static void initialize() { - if (!sInitialized) { - sInitialized = true; + private static boolean sInitialized = false; - sScrollFlagMap.put(SCROLL_FLAG_SCROLL, AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL); - sScrollFlagMap.put(SCROLL_FLAG_EXIT_UNTIL_COLLAPSED, AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED); - sScrollFlagMap.put(SCROLL_FLAG_ENTER_ALWAYS, AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS); - sScrollFlagMap.put(SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED, AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED); - sScrollFlagMap.put(SCROLL_FLAG_SNAP, AppBarLayout.LayoutParams.SCROLL_FLAG_SNAP); - } - } + private static void initialize() { + if (!sInitialized) { + sInitialized = true; + + sScrollFlagMap.put(SCROLL_FLAG_SCROLL, AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL); + sScrollFlagMap.put(SCROLL_FLAG_EXIT_UNTIL_COLLAPSED, AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED); + sScrollFlagMap.put(SCROLL_FLAG_ENTER_ALWAYS, AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS); + sScrollFlagMap.put(SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED, AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED); + sScrollFlagMap.put(SCROLL_FLAG_SNAP, AppBarLayout.LayoutParams.SCROLL_FLAG_SNAP); + } + } - private static AppBarLayout.LayoutParams getLayoutParams(View v) { - initialize(); - AppBarLayout.LayoutParams result = null; - ViewGroup.LayoutParams layoutParams = v.getLayoutParams(); - if (null != layoutParams && layoutParams instanceof AppBarLayout.LayoutParams) { - result = (AppBarLayout.LayoutParams) layoutParams; - } - return result; + private static AppBarLayout.LayoutParams getLayoutParams(View v) { + initialize(); + AppBarLayout.LayoutParams result = null; + ViewGroup.LayoutParams layoutParams = v.getLayoutParams(); + if (null != layoutParams && layoutParams instanceof AppBarLayout.LayoutParams) { + result = (AppBarLayout.LayoutParams) layoutParams; + } + return result; + } + + static void setLayoutScrollFlags(View v, String scrollFlags) { + AppBarLayout.LayoutParams layoutParams = getLayoutParams(v); + if (null != layoutParams && !TextUtils.isEmpty(scrollFlags)) { + String[] listFlags = scrollFlags.split("\\|"); + int scrollFlag = 0; + for (String flag : listFlags) { + Integer flags = sScrollFlagMap.get(flag.trim()); + if (null != flags) { + scrollFlag |= flags; + } } - static void setLayoutScrollFlags(View v, String scrollFlags) { - AppBarLayout.LayoutParams layoutParams = getLayoutParams(v); - if (null != layoutParams && !TextUtils.isEmpty(scrollFlags)) { - String[] listFlags = scrollFlags.split("\\|"); - int scrollFlag = 0; - for (String flag : listFlags) { - Integer flags = sScrollFlagMap.get(flag.trim()); - if (null != flags) { - scrollFlag |= flags; - } - } - - if (scrollFlag != 0) { - layoutParams.setScrollFlags(scrollFlag); - } - } + if (scrollFlag != 0) { + layoutParams.setScrollFlags(scrollFlag); } + } } + } - private static class CollapsingToolbarLayoutParamsHelper { - private static final String COLLAPSE_MODE_OFF = "off"; - private static final String COLLAPSE_MODE_PARALLAX = "parallax"; - private static final String COLLAPSE_MODE_PIN = "pin"; + private static class CollapsingToolbarLayoutParamsHelper { + private static final String COLLAPSE_MODE_OFF = "off"; + private static final String COLLAPSE_MODE_PARALLAX = "parallax"; + private static final String COLLAPSE_MODE_PIN = "pin"; - private static final HashMap sCollapseModeMap = new HashMap<>(); + private static final HashMap sCollapseModeMap = new HashMap<>(); - private static boolean sInitialized = false; + private static boolean sInitialized = false; - private static void initialize() { - if (!sInitialized) { - sInitialized = true; - - sCollapseModeMap.put(COLLAPSE_MODE_OFF, CollapsingToolbarLayout.LayoutParams.COLLAPSE_MODE_OFF); - sCollapseModeMap.put(COLLAPSE_MODE_PARALLAX, CollapsingToolbarLayout.LayoutParams.COLLAPSE_MODE_PARALLAX); - sCollapseModeMap.put(COLLAPSE_MODE_PIN, CollapsingToolbarLayout.LayoutParams.COLLAPSE_MODE_PIN); - } - } + private static void initialize() { + if (!sInitialized) { + sInitialized = true; + sCollapseModeMap.put(COLLAPSE_MODE_OFF, CollapsingToolbarLayout.LayoutParams.COLLAPSE_MODE_OFF); + sCollapseModeMap.put(COLLAPSE_MODE_PARALLAX, CollapsingToolbarLayout.LayoutParams.COLLAPSE_MODE_PARALLAX); + sCollapseModeMap.put(COLLAPSE_MODE_PIN, CollapsingToolbarLayout.LayoutParams.COLLAPSE_MODE_PIN); + } + } - private static CollapsingToolbarLayout.LayoutParams getLayoutParams(View v) { - initialize(); - CollapsingToolbarLayout.LayoutParams result = null; - ViewGroup.LayoutParams layoutParams = v.getLayoutParams(); - if (null != layoutParams && layoutParams instanceof CollapsingToolbarLayout.LayoutParams) { - result = (CollapsingToolbarLayout.LayoutParams) layoutParams; - } - return result; - } - - static void setCollapseMode(View v, String mode) { - CollapsingToolbarLayout.LayoutParams layoutParams = getLayoutParams(v); - if (null != layoutParams) { - Integer collapseMode = sCollapseModeMap.get(mode); - if (null != collapseMode) { - layoutParams.setCollapseMode(collapseMode); - } - } - } - static void setParallaxMultiplier(View v, String multiplier) { - CollapsingToolbarLayout.LayoutParams layoutParams = getLayoutParams(v); - if (null != layoutParams && !TextUtils.isEmpty(multiplier)) { - layoutParams.setParallaxMultiplier(ParseHelper.parseFloat(multiplier)); - } + private static CollapsingToolbarLayout.LayoutParams getLayoutParams(View v) { + initialize(); + CollapsingToolbarLayout.LayoutParams result = null; + ViewGroup.LayoutParams layoutParams = v.getLayoutParams(); + if (null != layoutParams && layoutParams instanceof CollapsingToolbarLayout.LayoutParams) { + result = (CollapsingToolbarLayout.LayoutParams) layoutParams; + } + return result; + } + static void setCollapseMode(View v, String mode) { + CollapsingToolbarLayout.LayoutParams layoutParams = getLayoutParams(v); + if (null != layoutParams) { + Integer collapseMode = sCollapseModeMap.get(mode); + if (null != collapseMode) { + layoutParams.setCollapseMode(collapseMode); } + } } - private static class CoordinatorLayoutParamsHelper { - private static final HashMap sBehaviorMap = new HashMap<>(); + static void setParallaxMultiplier(View v, String multiplier) { + CollapsingToolbarLayout.LayoutParams layoutParams = getLayoutParams(v); + if (null != layoutParams && !TextUtils.isEmpty(multiplier)) { + layoutParams.setParallaxMultiplier(ParseHelper.parseFloat(multiplier)); + } - private static CoordinatorLayout.LayoutParams getLayoutParams(View v) { - CoordinatorLayout.LayoutParams result = null; - ViewGroup.LayoutParams layoutParams = v.getLayoutParams(); - if (null != layoutParams && layoutParams instanceof CoordinatorLayout.LayoutParams) { - result = (CoordinatorLayout.LayoutParams) layoutParams; - } - return result; - } + } + } + + private static class CoordinatorLayoutParamsHelper { + private static final HashMap sBehaviorMap = new HashMap<>(); + + private static CoordinatorLayout.LayoutParams getLayoutParams(View v) { + CoordinatorLayout.LayoutParams result = null; + ViewGroup.LayoutParams layoutParams = v.getLayoutParams(); + if (null != layoutParams && layoutParams instanceof CoordinatorLayout.LayoutParams) { + result = (CoordinatorLayout.LayoutParams) layoutParams; + } + return result; + } - static void setLayoutBehavior(View v, String behavior) { - CoordinatorLayout.LayoutParams layoutParams = getLayoutParams(v); - if (null != layoutParams && !TextUtils.isEmpty(behavior)) { - - //noinspection TryWithIdenticalCatches since there are min API requirements - try { - Class clazz = sBehaviorMap.get(behavior); - if (null == clazz) { - clazz = Class.forName(behavior); - sBehaviorMap.put(behavior, clazz); - } - Object behaviorObj = clazz.newInstance(); - if (null != behaviorObj && behaviorObj instanceof CoordinatorLayout.Behavior) { - layoutParams.setBehavior((CoordinatorLayout.Behavior) behaviorObj); - } - } catch (ClassNotFoundException e) { - if (ProteusConstants.isLoggingEnabled()) { - e.printStackTrace(); - } - } catch (InstantiationException e) { - if (ProteusConstants.isLoggingEnabled()) { - e.printStackTrace(); - } - } catch (IllegalAccessException e) { - if (ProteusConstants.isLoggingEnabled()) { - e.printStackTrace(); - } - } - } + static void setLayoutBehavior(View v, String behavior) { + CoordinatorLayout.LayoutParams layoutParams = getLayoutParams(v); + if (null != layoutParams && !TextUtils.isEmpty(behavior)) { + + //noinspection TryWithIdenticalCatches since there are min API requirements + try { + Class clazz = sBehaviorMap.get(behavior); + if (null == clazz) { + clazz = Class.forName(behavior); + sBehaviorMap.put(behavior, clazz); + } + Object behaviorObj = clazz.newInstance(); + if (null != behaviorObj && behaviorObj instanceof CoordinatorLayout.Behavior) { + layoutParams.setBehavior((CoordinatorLayout.Behavior) behaviorObj); + } + } catch (ClassNotFoundException e) { + if (ProteusConstants.isLoggingEnabled()) { + e.printStackTrace(); + } + } catch (InstantiationException e) { + if (ProteusConstants.isLoggingEnabled()) { + e.printStackTrace(); + } + } catch (IllegalAccessException e) { + if (ProteusConstants.isLoggingEnabled()) { + e.printStackTrace(); + } } + } } + } } diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/AppBarLayoutParser.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/AppBarLayoutParser.java index 3136f7a0..cf974ae0 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/AppBarLayoutParser.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/AppBarLayoutParser.java @@ -44,92 +44,92 @@ */ public class AppBarLayoutParser extends ViewTypeParser { - @NonNull - @Override - public String getType() { - return "AppBarLayout"; - } - - @Nullable - @Override - public String getParentType() { - return "LinearLayout"; - } - - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { - return new ProteusAppBarLayout(context); - } - - @Override - protected void addAttributeProcessors() { - - addAttributeProcessor("targetElevation", new DimensionAttributeProcessor() { - @Override - public void setDimension(V view, float dimension) { - //noinspection deprecation - view.setTargetElevation(dimension); - } - }); - - addAttributeProcessor("orientation", new AttributeProcessor() { - - private final Primitive VERTICAL = new Primitive(AppBarLayout.VERTICAL); - private final Primitive HORIZONTAL = new Primitive(AppBarLayout.HORIZONTAL); - - @Override - public void handleValue(V view, Value value) { - //noinspection WrongConstant - view.setOrientation(value.getAsInt()); - } - - @Override - public void handleResource(V view, Resource resource) { - Integer orientation = resource.getInteger(view.getContext()); - if (orientation != null) { - //noinspection WrongConstant - view.setOrientation(orientation); - } - } - - @Override - public void handleAttributeResource(V view, AttributeResource attribute) { - TypedArray a = attribute.apply(view.getContext()); - int orientation = a.getInt(0, AppBarLayout.VERTICAL); - //noinspection WrongConstant - view.setOrientation(orientation); - } - - @Override - public void handleStyleResource(V view, StyleResource style) { - TypedArray a = style.apply(view.getContext()); - int orientation = a.getInt(0, AppBarLayout.VERTICAL); - //noinspection WrongConstant - view.setOrientation(orientation); - } - - @Override - public Value compile(@Nullable Value value, Context context) { - if (null != value && value.isPrimitive()) { - String string = value.getAsString(); - if ("vertical".equals(string)) { - return VERTICAL; - } else { - return HORIZONTAL; - } - } else { - return VERTICAL; - } - } - }); - - addAttributeProcessor("expanded", new BooleanAttributeProcessor() { - @Override - public void setBoolean(V view, boolean value) { - view.setExpanded(value); - } - }); - - } + @NonNull + @Override + public String getType() { + return "AppBarLayout"; + } + + @Nullable + @Override + public String getParentType() { + return "LinearLayout"; + } + + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { + return new ProteusAppBarLayout(context); + } + + @Override + protected void addAttributeProcessors() { + + addAttributeProcessor("targetElevation", new DimensionAttributeProcessor() { + @Override + public void setDimension(V view, float dimension) { + //noinspection deprecation + view.setTargetElevation(dimension); + } + }); + + addAttributeProcessor("orientation", new AttributeProcessor() { + + private final Primitive VERTICAL = new Primitive(AppBarLayout.VERTICAL); + private final Primitive HORIZONTAL = new Primitive(AppBarLayout.HORIZONTAL); + + @Override + public void handleValue(V view, Value value) { + //noinspection WrongConstant + view.setOrientation(value.getAsInt()); + } + + @Override + public void handleResource(V view, Resource resource) { + Integer orientation = resource.getInteger(view.getContext()); + if (orientation != null) { + //noinspection WrongConstant + view.setOrientation(orientation); + } + } + + @Override + public void handleAttributeResource(V view, AttributeResource attribute) { + TypedArray a = attribute.apply(view.getContext()); + int orientation = a.getInt(0, AppBarLayout.VERTICAL); + //noinspection WrongConstant + view.setOrientation(orientation); + } + + @Override + public void handleStyleResource(V view, StyleResource style) { + TypedArray a = style.apply(view.getContext()); + int orientation = a.getInt(0, AppBarLayout.VERTICAL); + //noinspection WrongConstant + view.setOrientation(orientation); + } + + @Override + public Value compile(@Nullable Value value, Context context) { + if (null != value && value.isPrimitive()) { + String string = value.getAsString(); + if ("vertical".equals(string)) { + return VERTICAL; + } else { + return HORIZONTAL; + } + } else { + return VERTICAL; + } + } + }); + + addAttributeProcessor("expanded", new BooleanAttributeProcessor() { + @Override + public void setBoolean(V view, boolean value) { + view.setExpanded(value); + } + }); + + } } diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/BottomNavigationViewParser.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/BottomNavigationViewParser.java index e105cf9f..dd49d58e 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/BottomNavigationViewParser.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/BottomNavigationViewParser.java @@ -42,100 +42,100 @@ */ public class BottomNavigationViewParser extends ViewTypeParser { - @NonNull - @Override - public String getType() { - return "BottomNavigationView"; - } - - @Nullable - @Override - public String getParentType() { - return "FrameLayout"; - } - - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { - return new ProteusBottomNavigationView(context); - } - - @Override - protected void addAttributeProcessors() { - - addAttributeProcessor("itemBackground", new AttributeProcessor() { - @Override - public void handleValue(V view, Value value) { - throw new IllegalArgumentException("itemBackground must be a drawable resource id"); - } - - @Override - public void handleResource(V view, Resource resource) { - view.setItemBackgroundResource(resource.resId); - } - - @Override - public void handleAttributeResource(V view, AttributeResource attribute) { - throw new IllegalArgumentException("itemBackground must be a drawable resource id"); - } - - @Override - public void handleStyleResource(V view, StyleResource style) { - throw new IllegalArgumentException("itemBackground must be a drawable resource id"); - } - }); - - addAttributeProcessor("itemIconTint", new ColorResourceProcessor() { - @Override - public void setColor(V view, int color) { - throw new IllegalArgumentException("itemIconTint must be a color state list"); - } - - @Override - public void setColor(V view, ColorStateList colors) { - view.setItemIconTintList(colors); - } - }); - - addAttributeProcessor("itemTextColor", new ColorResourceProcessor() { - @Override - public void setColor(V view, int color) { - throw new IllegalArgumentException("itemIconTint must be a color state list"); - } - - @Override - public void setColor(V view, ColorStateList colors) { - view.setItemTextColor(colors); - } - }); - - addAttributeProcessor("menu", new AttributeProcessor() { - @Override - public void handleValue(V view, Value value) { - throw new IllegalArgumentException("menu must be a R.menu."); - } - - @Override - public void handleResource(V view, Resource resource) { - Integer id = resource.getInteger(view.getContext()); - if (null != id) { - view.inflateMenu(id); - } - } - - @Override - public void handleAttributeResource(V view, AttributeResource attribute) { - TypedArray a = attribute.apply(view.getContext()); - int id = a.getResourceId(0, 0); - view.inflateMenu(id); - } - - @Override - public void handleStyleResource(V view, StyleResource style) { - TypedArray a = style.apply(view.getContext()); - int id = a.getResourceId(0, 0); - view.inflateMenu(id); - } - }); - } + @NonNull + @Override + public String getType() { + return "BottomNavigationView"; + } + + @Nullable + @Override + public String getParentType() { + return "FrameLayout"; + } + + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { + return new ProteusBottomNavigationView(context); + } + + @Override + protected void addAttributeProcessors() { + + addAttributeProcessor("itemBackground", new AttributeProcessor() { + @Override + public void handleValue(V view, Value value) { + throw new IllegalArgumentException("itemBackground must be a drawable resource id"); + } + + @Override + public void handleResource(V view, Resource resource) { + view.setItemBackgroundResource(resource.resId); + } + + @Override + public void handleAttributeResource(V view, AttributeResource attribute) { + throw new IllegalArgumentException("itemBackground must be a drawable resource id"); + } + + @Override + public void handleStyleResource(V view, StyleResource style) { + throw new IllegalArgumentException("itemBackground must be a drawable resource id"); + } + }); + + addAttributeProcessor("itemIconTint", new ColorResourceProcessor() { + @Override + public void setColor(V view, int color) { + throw new IllegalArgumentException("itemIconTint must be a color state list"); + } + + @Override + public void setColor(V view, ColorStateList colors) { + view.setItemIconTintList(colors); + } + }); + + addAttributeProcessor("itemTextColor", new ColorResourceProcessor() { + @Override + public void setColor(V view, int color) { + throw new IllegalArgumentException("itemIconTint must be a color state list"); + } + + @Override + public void setColor(V view, ColorStateList colors) { + view.setItemTextColor(colors); + } + }); + + addAttributeProcessor("menu", new AttributeProcessor() { + @Override + public void handleValue(V view, Value value) { + throw new IllegalArgumentException("menu must be a R.menu."); + } + + @Override + public void handleResource(V view, Resource resource) { + Integer id = resource.getInteger(view.getContext()); + if (null != id) { + view.inflateMenu(id); + } + } + + @Override + public void handleAttributeResource(V view, AttributeResource attribute) { + TypedArray a = attribute.apply(view.getContext()); + int id = a.getResourceId(0, 0); + view.inflateMenu(id); + } + + @Override + public void handleStyleResource(V view, StyleResource style) { + TypedArray a = style.apply(view.getContext()); + int id = a.getResourceId(0, 0); + view.inflateMenu(id); + } + }); + } } diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/CollapsingToolbarLayoutParser.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/CollapsingToolbarLayoutParser.java index b2ff9758..5b13bdf3 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/CollapsingToolbarLayoutParser.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/CollapsingToolbarLayoutParser.java @@ -42,117 +42,117 @@ public class CollapsingToolbarLayoutParser extends ViewTypeParser { - @NonNull - @Override - public String getType() { - return "CollapsingToolbarLayout"; - } - - @Nullable - @Override - public String getParentType() { - return "FrameLayout"; - } - - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { - return new ProteusCollapsingToolbarLayout(context); - } - - @Override - protected void addAttributeProcessors() { - - addAttributeProcessor("collapsedTitleGravity", new GravityAttributeProcessor() { - @Override - public void setGravity(V view, @Gravity int gravity) { - view.setCollapsedTitleGravity(gravity); - } - }); - - addAttributeProcessor("contentScrim", new DrawableResourceProcessor() { - @Override - public void setDrawable(V view, Drawable drawable) { - view.setContentScrim(drawable); - } - }); - - addAttributeProcessor("expandedTitleGravity", new GravityAttributeProcessor() { - @Override - public void setGravity(V view, @Gravity int gravity) { - view.setExpandedTitleGravity(gravity); - } - }); - - addAttributeProcessor("expandedTitleMargin", new DimensionAttributeProcessor() { - @Override - public void setDimension(V view, float dimension) { - view.setExpandedTitleMargin((int) dimension, (int) dimension, (int) dimension, (int) dimension); - } - }); - - addAttributeProcessor("expandedTitleMarginBottom", new DimensionAttributeProcessor() { - @Override - public void setDimension(V view, float dimension) { - view.setExpandedTitleMarginBottom((int) dimension); - } - }); - - addAttributeProcessor("expandedTitleMarginEnd", new DimensionAttributeProcessor() { - @Override - public void setDimension(V view, float dimension) { - view.setExpandedTitleMarginEnd((int) dimension); - } - }); - - addAttributeProcessor("expandedTitleMarginStart", new DimensionAttributeProcessor() { - @Override - public void setDimension(V view, float dimension) { - view.setExpandedTitleMarginStart((int) dimension); - } - }); - - addAttributeProcessor("expandedTitleMarginTop", new DimensionAttributeProcessor() { - @Override - public void setDimension(V view, float dimension) { - view.setExpandedTitleMarginTop((int) dimension); - } - }); - - addAttributeProcessor("scrimAnimationDuration", new NumberAttributeProcessor() { - @Override - public void setNumber(V view, @NonNull Number value) { - view.setScrimAnimationDuration(value.longValue()); - } - }); - - - addAttributeProcessor("scrimVisibleHeightTrigger", new DimensionAttributeProcessor() { - @Override - public void setDimension(V view, float dimension) { - view.setScrimVisibleHeightTrigger((int) dimension); - } - }); - - addAttributeProcessor("statusBarScrim", new DrawableResourceProcessor() { - @Override - public void setDrawable(V view, Drawable drawable) { - view.setStatusBarScrim(drawable); - } - }); - - addAttributeProcessor("title", new StringAttributeProcessor() { - @Override - public void setString(V view, String value) { - view.setTitle(value); - } - }); - - addAttributeProcessor("titleEnabled", new BooleanAttributeProcessor() { - @Override - public void setBoolean(V view, boolean value) { - view.setTitleEnabled(value); - } - }); - } + @NonNull + @Override + public String getType() { + return "CollapsingToolbarLayout"; + } + + @Nullable + @Override + public String getParentType() { + return "FrameLayout"; + } + + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { + return new ProteusCollapsingToolbarLayout(context); + } + + @Override + protected void addAttributeProcessors() { + + addAttributeProcessor("collapsedTitleGravity", new GravityAttributeProcessor() { + @Override + public void setGravity(V view, @Gravity int gravity) { + view.setCollapsedTitleGravity(gravity); + } + }); + + addAttributeProcessor("contentScrim", new DrawableResourceProcessor() { + @Override + public void setDrawable(V view, Drawable drawable) { + view.setContentScrim(drawable); + } + }); + + addAttributeProcessor("expandedTitleGravity", new GravityAttributeProcessor() { + @Override + public void setGravity(V view, @Gravity int gravity) { + view.setExpandedTitleGravity(gravity); + } + }); + + addAttributeProcessor("expandedTitleMargin", new DimensionAttributeProcessor() { + @Override + public void setDimension(V view, float dimension) { + view.setExpandedTitleMargin((int) dimension, (int) dimension, (int) dimension, (int) dimension); + } + }); + + addAttributeProcessor("expandedTitleMarginBottom", new DimensionAttributeProcessor() { + @Override + public void setDimension(V view, float dimension) { + view.setExpandedTitleMarginBottom((int) dimension); + } + }); + + addAttributeProcessor("expandedTitleMarginEnd", new DimensionAttributeProcessor() { + @Override + public void setDimension(V view, float dimension) { + view.setExpandedTitleMarginEnd((int) dimension); + } + }); + + addAttributeProcessor("expandedTitleMarginStart", new DimensionAttributeProcessor() { + @Override + public void setDimension(V view, float dimension) { + view.setExpandedTitleMarginStart((int) dimension); + } + }); + + addAttributeProcessor("expandedTitleMarginTop", new DimensionAttributeProcessor() { + @Override + public void setDimension(V view, float dimension) { + view.setExpandedTitleMarginTop((int) dimension); + } + }); + + addAttributeProcessor("scrimAnimationDuration", new NumberAttributeProcessor() { + @Override + public void setNumber(V view, @NonNull Number value) { + view.setScrimAnimationDuration(value.longValue()); + } + }); + + + addAttributeProcessor("scrimVisibleHeightTrigger", new DimensionAttributeProcessor() { + @Override + public void setDimension(V view, float dimension) { + view.setScrimVisibleHeightTrigger((int) dimension); + } + }); + + addAttributeProcessor("statusBarScrim", new DrawableResourceProcessor() { + @Override + public void setDrawable(V view, Drawable drawable) { + view.setStatusBarScrim(drawable); + } + }); + + addAttributeProcessor("title", new StringAttributeProcessor() { + @Override + public void setString(V view, String value) { + view.setTitle(value); + } + }); + + addAttributeProcessor("titleEnabled", new BooleanAttributeProcessor() { + @Override + public void setBoolean(V view, boolean value) { + view.setTitleEnabled(value); + } + }); + } } diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/CoordinatorLayoutParser.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/CoordinatorLayoutParser.java index 7334268d..f6701f0a 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/CoordinatorLayoutParser.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/CoordinatorLayoutParser.java @@ -38,40 +38,40 @@ public class CoordinatorLayoutParser extends ViewTypeParser { - @NonNull - @Override - public String getType() { - return "CoordinatorLayout"; - } + @NonNull + @Override + public String getType() { + return "CoordinatorLayout"; + } - @Nullable - @Override - public String getParentType() { - return "ViewGroup"; - } + @Nullable + @Override + public String getParentType() { + return "ViewGroup"; + } - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { - return new ProteusCoordinatorLayout(context); - } + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { + return new ProteusCoordinatorLayout(context); + } - @Override - protected void addAttributeProcessors() { + @Override + protected void addAttributeProcessors() { - addAttributeProcessor("statusBarBackground", new DrawableResourceProcessor() { - @Override - public void setDrawable(V view, Drawable drawable) { - view.setStatusBarBackground(drawable); - } - }); + addAttributeProcessor("statusBarBackground", new DrawableResourceProcessor() { + @Override + public void setDrawable(V view, Drawable drawable) { + view.setStatusBarBackground(drawable); + } + }); - addAttributeProcessor("fitSystemWindows", new BooleanAttributeProcessor() { - @Override - public void setBoolean(V view, boolean value) { - view.setFitsSystemWindows(value); - } - }); + addAttributeProcessor("fitSystemWindows", new BooleanAttributeProcessor() { + @Override + public void setBoolean(V view, boolean value) { + view.setFitsSystemWindows(value); + } + }); - } + } } diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/FloatingActionButtonParser.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/FloatingActionButtonParser.java index 3fa28550..cf70da15 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/FloatingActionButtonParser.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/FloatingActionButtonParser.java @@ -43,84 +43,84 @@ public class FloatingActionButtonParser extends ViewTypeParser { - @NonNull - @Override - public String getType() { - return "FloatingActionButton"; - } - - @Nullable - @Override - public String getParentType() { - return "ImageButton"; - } - - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { - return new ProteusFloatingActionButton(context); - } - - @Override - protected void addAttributeProcessors() { - - addAttributeProcessor("elevation", new DimensionAttributeProcessor() { - @Override - public void setDimension(V view, float dimension) { - view.setCompatElevation(dimension); - } - }); - - addAttributeProcessor("fabSize", new NumberAttributeProcessor() { - - private final Primitive AUTO = new Primitive(FloatingActionButton.SIZE_AUTO); - private final Primitive MINI = new Primitive(FloatingActionButton.SIZE_MINI); - private final Primitive NORMAL = new Primitive(FloatingActionButton.SIZE_NORMAL); - - @Override - public void setNumber(V view, @NonNull Number value) { - //noinspection WrongConstant - view.setSize(value.intValue()); - } - - @Override - public Value compile(@Nullable Value value, Context context) { - if (value != null) { - String string = value.getAsString(); - switch (string) { - case "auto": - return AUTO; - case "mini": - return MINI; - case "normal": - return NORMAL; - default: - return AUTO; - } - } else { - return AUTO; - } - } - }); - - addAttributeProcessor("rippleColor", new ColorResourceProcessor() { - @Override - public void setColor(V view, int color) { - view.setRippleColor(color); - } - - @Override - public void setColor(V view, ColorStateList colors) { - throw new IllegalArgumentException("rippleColor must be a color int"); - } - }); - - addAttributeProcessor("useCompatPadding", new BooleanAttributeProcessor() { - @Override - public void setBoolean(V view, boolean value) { - view.setUseCompatPadding(value); - } - }); - - } + @NonNull + @Override + public String getType() { + return "FloatingActionButton"; + } + + @Nullable + @Override + public String getParentType() { + return "ImageButton"; + } + + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { + return new ProteusFloatingActionButton(context); + } + + @Override + protected void addAttributeProcessors() { + + addAttributeProcessor("elevation", new DimensionAttributeProcessor() { + @Override + public void setDimension(V view, float dimension) { + view.setCompatElevation(dimension); + } + }); + + addAttributeProcessor("fabSize", new NumberAttributeProcessor() { + + private final Primitive AUTO = new Primitive(FloatingActionButton.SIZE_AUTO); + private final Primitive MINI = new Primitive(FloatingActionButton.SIZE_MINI); + private final Primitive NORMAL = new Primitive(FloatingActionButton.SIZE_NORMAL); + + @Override + public void setNumber(V view, @NonNull Number value) { + //noinspection WrongConstant + view.setSize(value.intValue()); + } + + @Override + public Value compile(@Nullable Value value, Context context) { + if (value != null) { + String string = value.getAsString(); + switch (string) { + case "auto": + return AUTO; + case "mini": + return MINI; + case "normal": + return NORMAL; + default: + return AUTO; + } + } else { + return AUTO; + } + } + }); + + addAttributeProcessor("rippleColor", new ColorResourceProcessor() { + @Override + public void setColor(V view, int color) { + view.setRippleColor(color); + } + + @Override + public void setColor(V view, ColorStateList colors) { + throw new IllegalArgumentException("rippleColor must be a color int"); + } + }); + + addAttributeProcessor("useCompatPadding", new BooleanAttributeProcessor() { + @Override + public void setBoolean(V view, boolean value) { + view.setUseCompatPadding(value); + } + }); + + } } diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusAppBarLayout.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusAppBarLayout.java index df90ecc3..29c749af 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusAppBarLayout.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusAppBarLayout.java @@ -31,25 +31,25 @@ public class ProteusAppBarLayout extends AppBarLayout implements ProteusView { - private Manager manager; - - public ProteusAppBarLayout(ProteusContext context) { - super(context); - } - - @Override - public Manager getViewManager() { - return manager; - } - - @Override - public void setViewManager(@NonNull Manager manager) { - this.manager = manager; - } - - @NonNull - @Override - public View getAsView() { - return this; - } + private Manager manager; + + public ProteusAppBarLayout(ProteusContext context) { + super(context); + } + + @Override + public Manager getViewManager() { + return manager; + } + + @Override + public void setViewManager(@NonNull Manager manager) { + this.manager = manager; + } + + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusBottomNavigationView.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusBottomNavigationView.java index e0aa064c..2844ac76 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusBottomNavigationView.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusBottomNavigationView.java @@ -31,25 +31,25 @@ public class ProteusBottomNavigationView extends BottomNavigationView implements ProteusView { - private Manager manager; - - public ProteusBottomNavigationView(ProteusContext context) { - super(context); - } - - @Override - public Manager getViewManager() { - return manager; - } - - @Override - public void setViewManager(@NonNull Manager manager) { - this.manager = manager; - } - - @NonNull - @Override - public View getAsView() { - return this; - } + private Manager manager; + + public ProteusBottomNavigationView(ProteusContext context) { + super(context); + } + + @Override + public Manager getViewManager() { + return manager; + } + + @Override + public void setViewManager(@NonNull Manager manager) { + this.manager = manager; + } + + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusCollapsingToolbarLayout.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusCollapsingToolbarLayout.java index 10540d13..0d3e7844 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusCollapsingToolbarLayout.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusCollapsingToolbarLayout.java @@ -31,25 +31,25 @@ public class ProteusCollapsingToolbarLayout extends CollapsingToolbarLayout implements ProteusView { - private Manager manager; - - public ProteusCollapsingToolbarLayout(ProteusContext context) { - super(context); - } - - @Override - public Manager getViewManager() { - return manager; - } - - @Override - public void setViewManager(@NonNull Manager manager) { - this.manager = manager; - } - - @NonNull - @Override - public View getAsView() { - return this; - } + private Manager manager; + + public ProteusCollapsingToolbarLayout(ProteusContext context) { + super(context); + } + + @Override + public Manager getViewManager() { + return manager; + } + + @Override + public void setViewManager(@NonNull Manager manager) { + this.manager = manager; + } + + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusCoordinatorLayout.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusCoordinatorLayout.java index 74cb05cf..cf1c2e72 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusCoordinatorLayout.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusCoordinatorLayout.java @@ -31,25 +31,25 @@ public class ProteusCoordinatorLayout extends CoordinatorLayout implements ProteusView { - private Manager manager; - - public ProteusCoordinatorLayout(ProteusContext context) { - super(context); - } - - @Override - public Manager getViewManager() { - return manager; - } - - @Override - public void setViewManager(@NonNull Manager manager) { - this.manager = manager; - } - - @NonNull - @Override - public View getAsView() { - return this; - } + private Manager manager; + + public ProteusCoordinatorLayout(ProteusContext context) { + super(context); + } + + @Override + public Manager getViewManager() { + return manager; + } + + @Override + public void setViewManager(@NonNull Manager manager) { + this.manager = manager; + } + + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusFloatingActionButton.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusFloatingActionButton.java index 81690cc3..7bfa6516 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusFloatingActionButton.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusFloatingActionButton.java @@ -31,25 +31,25 @@ public class ProteusFloatingActionButton extends FloatingActionButton implements ProteusView { - private Manager manager; - - public ProteusFloatingActionButton(ProteusContext context) { - super(context); - } - - @Override - public Manager getViewManager() { - return manager; - } - - @Override - public void setViewManager(@NonNull Manager manager) { - this.manager = manager; - } - - @NonNull - @Override - public View getAsView() { - return this; - } + private Manager manager; + + public ProteusFloatingActionButton(ProteusContext context) { + super(context); + } + + @Override + public Manager getViewManager() { + return manager; + } + + @Override + public void setViewManager(@NonNull Manager manager) { + this.manager = manager; + } + + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusNavigationView.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusNavigationView.java index 29c7396a..0664eac4 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusNavigationView.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusNavigationView.java @@ -31,25 +31,25 @@ public class ProteusNavigationView extends NavigationView implements ProteusView { - private Manager manager; - - public ProteusNavigationView(ProteusContext context) { - super(context); - } - - @Override - public Manager getViewManager() { - return manager; - } - - @Override - public void setViewManager(@NonNull Manager manager) { - this.manager = manager; - } - - @NonNull - @Override - public View getAsView() { - return this; - } + private Manager manager; + + public ProteusNavigationView(ProteusContext context) { + super(context); + } + + @Override + public Manager getViewManager() { + return manager; + } + + @Override + public void setViewManager(@NonNull Manager manager) { + this.manager = manager; + } + + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusTabLayout.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusTabLayout.java index e0472964..6885650e 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusTabLayout.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusTabLayout.java @@ -31,25 +31,25 @@ public class ProteusTabLayout extends TabLayout implements ProteusView { - private Manager manager; - - public ProteusTabLayout(ProteusContext context) { - super(context); - } - - @Override - public Manager getViewManager() { - return manager; - } - - @Override - public void setViewManager(@NonNull Manager manager) { - this.manager = manager; - } - - @NonNull - @Override - public View getAsView() { - return this; - } + private Manager manager; + + public ProteusTabLayout(ProteusContext context) { + super(context); + } + + @Override + public Manager getViewManager() { + return manager; + } + + @Override + public void setViewManager(@NonNull Manager manager) { + this.manager = manager; + } + + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusTextInputEditText.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusTextInputEditText.java index bff8a61d..c14124c7 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusTextInputEditText.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusTextInputEditText.java @@ -31,25 +31,25 @@ public class ProteusTextInputEditText extends TextInputEditText implements ProteusView { - private Manager manager; - - public ProteusTextInputEditText(ProteusContext context) { - super(context); - } - - @Override - public Manager getViewManager() { - return manager; - } - - @Override - public void setViewManager(@NonNull Manager manager) { - this.manager = manager; - } - - @NonNull - @Override - public View getAsView() { - return this; - } + private Manager manager; + + public ProteusTextInputEditText(ProteusContext context) { + super(context); + } + + @Override + public Manager getViewManager() { + return manager; + } + + @Override + public void setViewManager(@NonNull Manager manager) { + this.manager = manager; + } + + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusTextInputLayout.java b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusTextInputLayout.java index 5fd41021..03896435 100644 --- a/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusTextInputLayout.java +++ b/design/src/main/java/com/flipkart/android/proteus/support/design/widget/ProteusTextInputLayout.java @@ -31,25 +31,25 @@ public class ProteusTextInputLayout extends TextInputLayout implements ProteusView { - private Manager manager; - - public ProteusTextInputLayout(ProteusContext context) { - super(context); - } - - @Override - public Manager getViewManager() { - return manager; - } - - @Override - public void setViewManager(@NonNull Manager manager) { - this.manager = manager; - } - - @NonNull - @Override - public View getAsView() { - return this; - } + private Manager manager; + + public ProteusTextInputLayout(ProteusContext context) { + super(context); + } + + @Override + public Manager getViewManager() { + return manager; + } + + @Override + public void setViewManager(@NonNull Manager manager) { + this.manager = manager; + } + + @NonNull + @Override + public View getAsView() { + return this; + } } From d7a103122f8204fdfa102c964666c84ca789ab3d Mon Sep 17 00:00:00 2001 From: Aditya Sharat Date: Sun, 13 Jan 2019 00:47:39 +0000 Subject: [PATCH 16/19] reformat code --- .../proteus/gson/CustomValueTypeAdapter.java | 8 +- .../gson/CustomValueTypeAdapterCreator.java | 2 +- .../android/proteus/gson/DefaultModule.java | 1364 ++++++++--------- .../gson/ProteusTypeAdapterFactory.java | 836 +++++----- .../gson/ProteusTypeAdapterFactoryTest.java | 120 +- 5 files changed, 1165 insertions(+), 1165 deletions(-) diff --git a/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/CustomValueTypeAdapter.java b/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/CustomValueTypeAdapter.java index 6afb9542..9309c42d 100644 --- a/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/CustomValueTypeAdapter.java +++ b/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/CustomValueTypeAdapter.java @@ -26,10 +26,10 @@ */ public abstract class CustomValueTypeAdapter extends TypeAdapter { - public final int type; + public final int type; - protected CustomValueTypeAdapter(int type) { - this.type = type; - } + protected CustomValueTypeAdapter(int type) { + this.type = type; + } } diff --git a/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/CustomValueTypeAdapterCreator.java b/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/CustomValueTypeAdapterCreator.java index e10a5f64..e4bfcf8b 100644 --- a/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/CustomValueTypeAdapterCreator.java +++ b/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/CustomValueTypeAdapterCreator.java @@ -25,6 +25,6 @@ */ public abstract class CustomValueTypeAdapterCreator { - public abstract CustomValueTypeAdapter create(int type, ProteusTypeAdapterFactory factory); + public abstract CustomValueTypeAdapter create(int type, ProteusTypeAdapterFactory factory); } diff --git a/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/DefaultModule.java b/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/DefaultModule.java index 07cf9fb8..50d7f66e 100644 --- a/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/DefaultModule.java +++ b/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/DefaultModule.java @@ -47,698 +47,698 @@ */ public class DefaultModule implements ProteusTypeAdapterFactory.Module { - /** - * - */ - public final CustomValueTypeAdapterCreator ATTRIBUTE_RESOURCE = new CustomValueTypeAdapterCreator() { + /** + * + */ + public final CustomValueTypeAdapterCreator ATTRIBUTE_RESOURCE = new CustomValueTypeAdapterCreator() { + @Override + public CustomValueTypeAdapter create(int type, ProteusTypeAdapterFactory factory) { + return new CustomValueTypeAdapter(type) { + @Override + public void write(JsonWriter out, AttributeResource value) throws IOException { + out.value(value.attributeId); + } + + @Override + public AttributeResource read(JsonReader in) throws IOException { + return AttributeResource.valueOf(Integer.parseInt(in.nextString())); + } + }; + } + }; + + /** + * + */ + public final CustomValueTypeAdapterCreator BINDING = new CustomValueTypeAdapterCreator() { + @Override + public CustomValueTypeAdapter create(int type, final ProteusTypeAdapterFactory factory) { + return new CustomValueTypeAdapter(type) { + + @Override + public void write(JsonWriter out, Binding value) throws IOException { + out.value(value.toString()); + } + + @Override + public Binding read(JsonReader in) throws IOException { + return Binding.valueOf(in.nextString(), factory.getContext(), ProteusTypeAdapterFactory.PROTEUS_INSTANCE_HOLDER.getProteus().functions); + } + }; + } + }; + + /** + * + */ + public final CustomValueTypeAdapterCreator COLOR_INT = new CustomValueTypeAdapterCreator() { + @Override + public CustomValueTypeAdapter create(int type, ProteusTypeAdapterFactory factory) { + return new CustomValueTypeAdapter(type) { + @Override + public void write(JsonWriter out, Color.Int color) throws IOException { + out.value(color.value); + } + + @Override + public Color.Int read(JsonReader in) throws IOException { + return Color.Int.valueOf(Integer.parseInt(in.nextString())); + } + }; + } + }; + + /** + * + */ + public final CustomValueTypeAdapterCreator COLOR_STATE_LIST = new CustomValueTypeAdapterCreator() { + @Override + public CustomValueTypeAdapter create(int type, ProteusTypeAdapterFactory factory) { + return new CustomValueTypeAdapter(type) { + + private static final String KEY_STATES = "s"; + private static final String KEY_COLORS = "c"; + + @Override + public void write(JsonWriter out, Color.StateList value) throws IOException { + out.beginObject(); + + out.name(KEY_STATES); + out.value(ProteusTypeAdapterFactory.writeArrayOfIntArrays(value.states)); + + out.name(KEY_COLORS); + out.value(ProteusTypeAdapterFactory.writeArrayOfInts(value.colors)); + + out.endObject(); + } + + @Override + public Color.StateList read(JsonReader in) throws IOException { + in.beginObject(); + + in.nextName(); + int[][] states = ProteusTypeAdapterFactory.readArrayOfIntArrays(in.nextString()); + + in.nextName(); + int colors[] = ProteusTypeAdapterFactory.readArrayOfInts(in.nextString()); + + in.endObject(); + + return Color.StateList.valueOf(states, colors); + } + }; + } + }; + + /** + * + */ + public final CustomValueTypeAdapterCreator DIMENSION = new CustomValueTypeAdapterCreator() { + @Override + public CustomValueTypeAdapter create(int type, ProteusTypeAdapterFactory factory) { + return new CustomValueTypeAdapter(type) { + @Override + public void write(JsonWriter out, Dimension value) throws IOException { + out.value(value.toString()); + } + + @Override + public Dimension read(JsonReader in) throws IOException { + return Dimension.valueOf(in.nextString()); + } + }; + } + }; + + /** + * + */ + public final CustomValueTypeAdapterCreator DRAWABLE_COLOR = new CustomValueTypeAdapterCreator() { + @Override + public CustomValueTypeAdapter create(int type, final ProteusTypeAdapterFactory factory) { + return new CustomValueTypeAdapter(type) { + @Override + public void write(JsonWriter out, DrawableValue.ColorValue value) throws IOException { + factory.COMPILED_VALUE_TYPE_ADAPTER.write(out, value.color); + } + + @Override + public DrawableValue.ColorValue read(JsonReader in) throws IOException { + return DrawableValue.ColorValue.valueOf(factory.COMPILED_VALUE_TYPE_ADAPTER.read(in), factory.getContext()); + } + }; + } + }; + + /** + * + */ + public final CustomValueTypeAdapterCreator DRAWABLE_LAYER_LIST = new CustomValueTypeAdapterCreator() { + @Override + public CustomValueTypeAdapter create(int type, final ProteusTypeAdapterFactory factory) { + return new CustomValueTypeAdapter(type) { + + private static final String KEY_IDS = "i"; + private static final String KEY_LAYERS = "l"; + + @Override + public void write(JsonWriter out, DrawableValue.LayerListValue value) throws IOException { + + out.beginObject(); + + out.name(KEY_IDS); + Iterator i = value.getIds(); + out.beginArray(); + while (i.hasNext()) { + out.value(i.next()); + } + out.endArray(); + + out.name(KEY_LAYERS); + Iterator l = value.getLayers(); + out.beginArray(); + while (l.hasNext()) { + factory.COMPILED_VALUE_TYPE_ADAPTER.write(out, l.next()); + } + out.endArray(); + + out.endObject(); + } + + @Override + public DrawableValue.LayerListValue read(JsonReader in) throws IOException { + + in.beginObject(); + + in.nextName(); + int[] ids = new int[0]; + in.beginArray(); + while (in.hasNext()) { + ids = Arrays.copyOf(ids, ids.length + 1); + ids[ids.length - 1] = Integer.parseInt(in.nextString()); + } + in.endArray(); + + in.nextName(); + Value[] layers = new Value[0]; + in.beginArray(); + while (in.hasNext()) { + layers = Arrays.copyOf(layers, layers.length + 1); + layers[layers.length - 1] = factory.COMPILED_VALUE_TYPE_ADAPTER.read(in); + } + in.endArray(); + + in.endObject(); + + return DrawableValue.LayerListValue.valueOf(ids, layers); + } + }; + } + }; + + /** + * + */ + public final CustomValueTypeAdapterCreator DRAWABLE_LEVEL_LIST = new CustomValueTypeAdapterCreator() { + @Override + public CustomValueTypeAdapter create(int type, final ProteusTypeAdapterFactory factory) { + return new CustomValueTypeAdapter(type) { + + private static final String KEY_MIN_LEVEL = "i"; + private static final String KEY_MAX_LEVEL = "a"; + private static final String KEY_DRAWABLE = "d"; + + @Override + public void write(JsonWriter out, DrawableValue.LevelListValue value) throws IOException { + out.beginArray(); + Iterator iterator = value.getLevels(); + DrawableValue.LevelListValue.Level level; + while (iterator.hasNext()) { + level = iterator.next(); + + out.beginObject(); + + out.name(KEY_MIN_LEVEL); + out.value(level.minLevel); + + out.name(KEY_MAX_LEVEL); + out.value(level.maxLevel); + + out.name(KEY_DRAWABLE); + factory.COMPILED_VALUE_TYPE_ADAPTER.write(out, level.drawable); + + out.endObject(); + } + out.endArray(); + } + + @Override + public DrawableValue.LevelListValue read(JsonReader in) throws IOException { + DrawableValue.LevelListValue.Level[] levels = new DrawableValue.LevelListValue.Level[0]; + + in.beginArray(); + int minLevel, maxLevel; + Value drawable; + DrawableValue.LevelListValue.Level level; + + while (in.hasNext()) { + in.beginObject(); + + in.nextName(); + minLevel = Integer.parseInt(in.nextString()); + + in.nextName(); + maxLevel = Integer.parseInt(in.nextString()); + + in.nextName(); + drawable = factory.COMPILED_VALUE_TYPE_ADAPTER.read(in); + + level = DrawableValue.LevelListValue.Level.valueOf(minLevel, maxLevel, drawable, factory.getContext()); + + levels = Arrays.copyOf(levels, levels.length + 1); + levels[levels.length - 1] = level; + + in.endObject(); + } + + in.endArray(); + + return DrawableValue.LevelListValue.value(levels); + } + }; + } + }; + + /** + * + */ + public final CustomValueTypeAdapterCreator DRAWABLE_SHAPE = new CustomValueTypeAdapterCreator() { + @Override + public CustomValueTypeAdapter create(int type, final ProteusTypeAdapterFactory factory) { + return new CustomValueTypeAdapter(type) { + @Override + public void write(JsonWriter out, DrawableValue.ShapeValue value) throws IOException { + // TODO: remove mock + out.value("#00000000"); + } + + @Override + public DrawableValue.ShapeValue read(JsonReader in) throws IOException { + // TODO: remove mock + in.skipValue(); + return DrawableValue.ShapeValue.valueOf(0, null, null); + } + }; + } + }; + + /** + * + */ + public final CustomValueTypeAdapterCreator DRAWABLE_RIPPLE = new CustomValueTypeAdapterCreator() { + @Override + public CustomValueTypeAdapter create(int type, final ProteusTypeAdapterFactory factory) { + return new CustomValueTypeAdapter(type) { + + private static final String KEY_COLOR = "c"; + private static final String KEY_MASK = "m"; + private static final String KEY_CONTENT = "t"; + private static final String KEY_DEFAULT_BACKGROUND = "d"; + + @Override + public void write(JsonWriter out, DrawableValue.RippleValue value) throws IOException { + out.beginObject(); + + out.name(KEY_COLOR); + factory.COMPILED_VALUE_TYPE_ADAPTER.write(out, value.color); + + if (value.mask != null) { + out.name(KEY_MASK); + factory.COMPILED_VALUE_TYPE_ADAPTER.write(out, value.mask); + } + + if (value.content != null) { + out.name(KEY_CONTENT); + factory.COMPILED_VALUE_TYPE_ADAPTER.write(out, value.content); + } + + if (value.defaultBackground != null) { + out.name(KEY_DEFAULT_BACKGROUND); + factory.COMPILED_VALUE_TYPE_ADAPTER.write(out, value.defaultBackground); + } + + out.endObject(); + } + @Override - public CustomValueTypeAdapter create(int type, ProteusTypeAdapterFactory factory) { - return new CustomValueTypeAdapter(type) { - @Override - public void write(JsonWriter out, AttributeResource value) throws IOException { - out.value(value.attributeId); - } - - @Override - public AttributeResource read(JsonReader in) throws IOException { - return AttributeResource.valueOf(Integer.parseInt(in.nextString())); - } - }; - } - }; - - /** - * - */ - public final CustomValueTypeAdapterCreator BINDING = new CustomValueTypeAdapterCreator() { - @Override - public CustomValueTypeAdapter create(int type, final ProteusTypeAdapterFactory factory) { - return new CustomValueTypeAdapter(type) { - - @Override - public void write(JsonWriter out, Binding value) throws IOException { - out.value(value.toString()); - } - - @Override - public Binding read(JsonReader in) throws IOException { - return Binding.valueOf(in.nextString(), factory.getContext(), ProteusTypeAdapterFactory.PROTEUS_INSTANCE_HOLDER.getProteus().functions); - } - }; - } - }; - - /** - * - */ - public final CustomValueTypeAdapterCreator COLOR_INT = new CustomValueTypeAdapterCreator() { - @Override - public CustomValueTypeAdapter create(int type, ProteusTypeAdapterFactory factory) { - return new CustomValueTypeAdapter(type) { - @Override - public void write(JsonWriter out, Color.Int color) throws IOException { - out.value(color.value); - } - - @Override - public Color.Int read(JsonReader in) throws IOException { - return Color.Int.valueOf(Integer.parseInt(in.nextString())); - } - }; + public DrawableValue.RippleValue read(JsonReader in) throws IOException { + + in.beginObject(); + + String name; + Value color = null, mask = null, content = null, defaultBackground = null; + + while (in.hasNext()) { + name = in.nextName(); + switch (name) { + case KEY_COLOR: + color = factory.COMPILED_VALUE_TYPE_ADAPTER.read(in); + break; + case KEY_MASK: + mask = factory.COMPILED_VALUE_TYPE_ADAPTER.read(in); + break; + case KEY_CONTENT: + content = factory.COMPILED_VALUE_TYPE_ADAPTER.read(in); + break; + case KEY_DEFAULT_BACKGROUND: + defaultBackground = factory.COMPILED_VALUE_TYPE_ADAPTER.read(in); + break; + default: + throw new IllegalStateException("Bad attribute '" + name + "'"); + } + } + + in.endObject(); + + if (color == null) { + throw new IllegalStateException("color is a required attribute in Ripple Drawable"); + } + + return DrawableValue.RippleValue.valueOf(color, mask, content, defaultBackground); } - }; - - /** - * - */ - public final CustomValueTypeAdapterCreator COLOR_STATE_LIST = new CustomValueTypeAdapterCreator() { - @Override - public CustomValueTypeAdapter create(int type, ProteusTypeAdapterFactory factory) { - return new CustomValueTypeAdapter(type) { - - private static final String KEY_STATES = "s"; - private static final String KEY_COLORS = "c"; - - @Override - public void write(JsonWriter out, Color.StateList value) throws IOException { - out.beginObject(); - - out.name(KEY_STATES); - out.value(ProteusTypeAdapterFactory.writeArrayOfIntArrays(value.states)); - - out.name(KEY_COLORS); - out.value(ProteusTypeAdapterFactory.writeArrayOfInts(value.colors)); - - out.endObject(); - } - - @Override - public Color.StateList read(JsonReader in) throws IOException { - in.beginObject(); - - in.nextName(); - int[][] states = ProteusTypeAdapterFactory.readArrayOfIntArrays(in.nextString()); - - in.nextName(); - int colors[] = ProteusTypeAdapterFactory.readArrayOfInts(in.nextString()); - - in.endObject(); - - return Color.StateList.valueOf(states, colors); - } - }; - } - }; - - /** - * - */ - public final CustomValueTypeAdapterCreator DIMENSION = new CustomValueTypeAdapterCreator() { - @Override - public CustomValueTypeAdapter create(int type, ProteusTypeAdapterFactory factory) { - return new CustomValueTypeAdapter(type) { - @Override - public void write(JsonWriter out, Dimension value) throws IOException { - out.value(value.toString()); - } - - @Override - public Dimension read(JsonReader in) throws IOException { - return Dimension.valueOf(in.nextString()); - } - }; - } - }; - - /** - * - */ - public final CustomValueTypeAdapterCreator DRAWABLE_COLOR = new CustomValueTypeAdapterCreator() { - @Override - public CustomValueTypeAdapter create(int type, final ProteusTypeAdapterFactory factory) { - return new CustomValueTypeAdapter(type) { - @Override - public void write(JsonWriter out, DrawableValue.ColorValue value) throws IOException { - factory.COMPILED_VALUE_TYPE_ADAPTER.write(out, value.color); - } - - @Override - public DrawableValue.ColorValue read(JsonReader in) throws IOException { - return DrawableValue.ColorValue.valueOf(factory.COMPILED_VALUE_TYPE_ADAPTER.read(in), factory.getContext()); - } - }; - } - }; - - /** - * - */ - public final CustomValueTypeAdapterCreator DRAWABLE_LAYER_LIST = new CustomValueTypeAdapterCreator() { - @Override - public CustomValueTypeAdapter create(int type, final ProteusTypeAdapterFactory factory) { - return new CustomValueTypeAdapter(type) { - - private static final String KEY_IDS = "i"; - private static final String KEY_LAYERS = "l"; - - @Override - public void write(JsonWriter out, DrawableValue.LayerListValue value) throws IOException { + }; + } + }; + + /** + * + */ + public final CustomValueTypeAdapterCreator DRAWABLE_STATE_LIST = new CustomValueTypeAdapterCreator() { + @Override + public CustomValueTypeAdapter create(int type, final ProteusTypeAdapterFactory factory) { + return new CustomValueTypeAdapter(type) { + + private static final String KEY_STATES = "s"; + private static final String KEY_VALUES = "v"; + + @Override + public void write(JsonWriter out, DrawableValue.StateListValue value) throws IOException { + out.beginObject(); + + out.name(KEY_STATES); + out.value(ProteusTypeAdapterFactory.writeArrayOfIntArrays(value.states)); + + out.name(KEY_VALUES); + out.beginArray(); + Iterator iterator = value.getValues(); + while (iterator.hasNext()) { + factory.COMPILED_VALUE_TYPE_ADAPTER.write(out, iterator.next()); + } + out.endArray(); + + out.endObject(); + } + + @Override + public DrawableValue.StateListValue read(JsonReader in) throws IOException { + + in.beginObject(); + + in.nextName(); + int[][] states = ProteusTypeAdapterFactory.readArrayOfIntArrays(in.nextString()); - out.beginObject(); + in.nextName(); + Value[] values = new Value[0]; - out.name(KEY_IDS); - Iterator i = value.getIds(); - out.beginArray(); - while (i.hasNext()) { - out.value(i.next()); - } - out.endArray(); + in.beginArray(); + while (in.hasNext()) { + values = Arrays.copyOf(values, values.length + 1); + values[values.length - 1] = factory.COMPILED_VALUE_TYPE_ADAPTER.read(in); + } + in.endArray(); - out.name(KEY_LAYERS); - Iterator l = value.getLayers(); - out.beginArray(); - while (l.hasNext()) { - factory.COMPILED_VALUE_TYPE_ADAPTER.write(out, l.next()); - } - out.endArray(); + in.endObject(); - out.endObject(); - } + return DrawableValue.StateListValue.valueOf(states, values); + } + }; + } + }; - @Override - public DrawableValue.LayerListValue read(JsonReader in) throws IOException { + /** + * + */ + public final CustomValueTypeAdapterCreator DRAWABLE_URL = new CustomValueTypeAdapterCreator() { + @Override + public CustomValueTypeAdapter create(int type, ProteusTypeAdapterFactory factory) { + return new CustomValueTypeAdapter(type) { + @Override + public void write(JsonWriter out, DrawableValue.UrlValue value) throws IOException { + out.value(value.url); + } - in.beginObject(); + @Override + public DrawableValue.UrlValue read(JsonReader in) throws IOException { + return DrawableValue.UrlValue.valueOf(in.nextString()); + } + }; + } + }; - in.nextName(); - int[] ids = new int[0]; - in.beginArray(); - while (in.hasNext()) { - ids = Arrays.copyOf(ids, ids.length + 1); - ids[ids.length - 1] = Integer.parseInt(in.nextString()); - } - in.endArray(); + /** + * + */ + public final CustomValueTypeAdapterCreator LAYOUT = new CustomValueTypeAdapterCreator() { + @Override + public CustomValueTypeAdapter create(int type, final ProteusTypeAdapterFactory factory) { + return new CustomValueTypeAdapter(type) { - in.nextName(); - Value[] layers = new Value[0]; - in.beginArray(); - while (in.hasNext()) { - layers = Arrays.copyOf(layers, layers.length + 1); - layers[layers.length - 1] = factory.COMPILED_VALUE_TYPE_ADAPTER.read(in); - } - in.endArray(); - - in.endObject(); - - return DrawableValue.LayerListValue.valueOf(ids, layers); - } - }; - } - }; - - /** - * - */ - public final CustomValueTypeAdapterCreator DRAWABLE_LEVEL_LIST = new CustomValueTypeAdapterCreator() { - @Override - public CustomValueTypeAdapter create(int type, final ProteusTypeAdapterFactory factory) { - return new CustomValueTypeAdapter(type) { - - private static final String KEY_MIN_LEVEL = "i"; - private static final String KEY_MAX_LEVEL = "a"; - private static final String KEY_DRAWABLE = "d"; - - @Override - public void write(JsonWriter out, DrawableValue.LevelListValue value) throws IOException { - out.beginArray(); - Iterator iterator = value.getLevels(); - DrawableValue.LevelListValue.Level level; - while (iterator.hasNext()) { - level = iterator.next(); - - out.beginObject(); - - out.name(KEY_MIN_LEVEL); - out.value(level.minLevel); - - out.name(KEY_MAX_LEVEL); - out.value(level.maxLevel); - - out.name(KEY_DRAWABLE); - factory.COMPILED_VALUE_TYPE_ADAPTER.write(out, level.drawable); + private static final String KEY_TYPE = "t"; + private static final String KEY_DATA = "d"; + private static final String KEY_ATTRIBUTES = "a"; + private static final String KEY_EXTRAS = "e"; + private static final String KEY_ATTRIBUTE_ID = "i"; + private static final String KEY_ATTRIBUTE_VALUE = "v"; - out.endObject(); - } - out.endArray(); - } - - @Override - public DrawableValue.LevelListValue read(JsonReader in) throws IOException { - DrawableValue.LevelListValue.Level[] levels = new DrawableValue.LevelListValue.Level[0]; + @Override + public void write(JsonWriter out, Layout value) throws IOException { + out.beginObject(); + + out.name(KEY_TYPE); + out.value(value.type); + + if (null != value.data) { + out.name(KEY_DATA); + out.beginObject(); + for (Map.Entry entry : value.data.entrySet()) { + out.name(entry.getKey()); + factory.COMPILED_VALUE_TYPE_ADAPTER.write(out, entry.getValue()); + } + out.endObject(); + } + + + if (null != value.attributes) { + out.name(KEY_ATTRIBUTES); + out.beginArray(); + for (Layout.Attribute attribute : value.attributes) { + out.beginObject(); + + out.name(KEY_ATTRIBUTE_ID); + out.value(attribute.id); + + out.name(KEY_ATTRIBUTE_VALUE); + factory.COMPILED_VALUE_TYPE_ADAPTER.write(out, attribute.value); + + out.endObject(); + } + out.endArray(); + } + + if (null != value.extras) { + out.name(KEY_EXTRAS); + factory.COMPILED_VALUE_TYPE_ADAPTER.write(out, value.extras); + } + + out.endObject(); + } - in.beginArray(); - int minLevel, maxLevel; - Value drawable; - DrawableValue.LevelListValue.Level level; + @Override + public Layout read(JsonReader in) throws IOException { + in.beginObject(); + + String name; + String type = null; + Map data = null; + List attributes = null; + ObjectValue extras = null; + + while (in.hasNext()) { + name = in.nextName(); + switch (name) { + case KEY_TYPE: + type = in.nextString(); + break; + case KEY_DATA: + data = readData(in); + break; + case KEY_ATTRIBUTES: + attributes = readAttributes(in); + break; + case KEY_EXTRAS: + extras = readExtras(in); + break; + default: + throw new IllegalStateException("Bad attribute '" + name + "'"); + } + } + + in.endObject(); + + if (null == type) { + throw new IllegalStateException("Layout must have type attribute!"); + } + + //noinspection ConstantConditions + return new Layout(type, attributes, data, extras); + } - while (in.hasNext()) { - in.beginObject(); - - in.nextName(); - minLevel = Integer.parseInt(in.nextString()); - - in.nextName(); - maxLevel = Integer.parseInt(in.nextString()); - - in.nextName(); - drawable = factory.COMPILED_VALUE_TYPE_ADAPTER.read(in); - - level = DrawableValue.LevelListValue.Level.valueOf(minLevel, maxLevel, drawable, factory.getContext()); - - levels = Arrays.copyOf(levels, levels.length + 1); - levels[levels.length - 1] = level; - - in.endObject(); - } - - in.endArray(); - - return DrawableValue.LevelListValue.value(levels); - } - }; - } - }; - - /** - * - */ - public final CustomValueTypeAdapterCreator DRAWABLE_SHAPE = new CustomValueTypeAdapterCreator() { - @Override - public CustomValueTypeAdapter create(int type, final ProteusTypeAdapterFactory factory) { - return new CustomValueTypeAdapter(type) { - @Override - public void write(JsonWriter out, DrawableValue.ShapeValue value) throws IOException { - // TODO: remove mock - out.value("#00000000"); - } - - @Override - public DrawableValue.ShapeValue read(JsonReader in) throws IOException { - // TODO: remove mock - in.skipValue(); - return DrawableValue.ShapeValue.valueOf(0, null, null); - } - }; + @Nullable + private Map readData(JsonReader in) throws IOException { + Map data = new HashMap<>(); + in.beginObject(); + String name; + Value value; + while (in.hasNext()) { + name = in.nextName(); + value = factory.COMPILED_VALUE_TYPE_ADAPTER.read(in); + data.put(name, value); + } + in.endObject(); + return data; } - }; - - /** - * - */ - public final CustomValueTypeAdapterCreator DRAWABLE_RIPPLE = new CustomValueTypeAdapterCreator() { - @Override - public CustomValueTypeAdapter create(int type, final ProteusTypeAdapterFactory factory) { - return new CustomValueTypeAdapter(type) { - - private static final String KEY_COLOR = "c"; - private static final String KEY_MASK = "m"; - private static final String KEY_CONTENT = "t"; - private static final String KEY_DEFAULT_BACKGROUND = "d"; - - @Override - public void write(JsonWriter out, DrawableValue.RippleValue value) throws IOException { - out.beginObject(); - - out.name(KEY_COLOR); - factory.COMPILED_VALUE_TYPE_ADAPTER.write(out, value.color); - if (value.mask != null) { - out.name(KEY_MASK); - factory.COMPILED_VALUE_TYPE_ADAPTER.write(out, value.mask); - } + @Nullable + private ObjectValue readExtras(JsonReader in) throws IOException { + return factory.COMPILED_VALUE_TYPE_ADAPTER.read(in).getAsObject(); + } - if (value.content != null) { - out.name(KEY_CONTENT); - factory.COMPILED_VALUE_TYPE_ADAPTER.write(out, value.content); - } - - if (value.defaultBackground != null) { - out.name(KEY_DEFAULT_BACKGROUND); - factory.COMPILED_VALUE_TYPE_ADAPTER.write(out, value.defaultBackground); - } + @Nullable + private List readAttributes(JsonReader in) throws IOException { + List attributes = new ArrayList<>(); + + in.beginArray(); + int id; + Value value; + while (in.hasNext()) { + in.beginObject(); + in.nextName(); + id = Integer.parseInt(in.nextString()); + in.nextName(); + value = factory.COMPILED_VALUE_TYPE_ADAPTER.read(in); + attributes.add(new Layout.Attribute(id, value)); + in.endObject(); + } + in.endArray(); + + return attributes; + } + }; + } + }; - out.endObject(); - } + /** + * + */ + public final CustomValueTypeAdapterCreator NESTED_BINDING = new CustomValueTypeAdapterCreator() { + @Override + public CustomValueTypeAdapter create(int type, final ProteusTypeAdapterFactory factory) { + return new CustomValueTypeAdapter(type) { + @Override + public void write(JsonWriter out, NestedBinding value) throws IOException { + factory.COMPILED_VALUE_TYPE_ADAPTER.write(out, value.getValue()); + } - @Override - public DrawableValue.RippleValue read(JsonReader in) throws IOException { - - in.beginObject(); - - String name; - Value color = null, mask = null, content = null, defaultBackground = null; - - while (in.hasNext()) { - name = in.nextName(); - switch (name) { - case KEY_COLOR: - color = factory.COMPILED_VALUE_TYPE_ADAPTER.read(in); - break; - case KEY_MASK: - mask = factory.COMPILED_VALUE_TYPE_ADAPTER.read(in); - break; - case KEY_CONTENT: - content = factory.COMPILED_VALUE_TYPE_ADAPTER.read(in); - break; - case KEY_DEFAULT_BACKGROUND: - defaultBackground = factory.COMPILED_VALUE_TYPE_ADAPTER.read(in); - break; - default: - throw new IllegalStateException("Bad attribute '" + name + "'"); - } - } - - in.endObject(); - - if (color == null) { - throw new IllegalStateException("color is a required attribute in Ripple Drawable"); - } - - return DrawableValue.RippleValue.valueOf(color, mask, content, defaultBackground); - } - }; - } - }; - - /** - * - */ - public final CustomValueTypeAdapterCreator DRAWABLE_STATE_LIST = new CustomValueTypeAdapterCreator() { - @Override - public CustomValueTypeAdapter create(int type, final ProteusTypeAdapterFactory factory) { - return new CustomValueTypeAdapter(type) { - - private static final String KEY_STATES = "s"; - private static final String KEY_VALUES = "v"; - - @Override - public void write(JsonWriter out, DrawableValue.StateListValue value) throws IOException { - out.beginObject(); - - out.name(KEY_STATES); - out.value(ProteusTypeAdapterFactory.writeArrayOfIntArrays(value.states)); - - out.name(KEY_VALUES); - out.beginArray(); - Iterator iterator = value.getValues(); - while (iterator.hasNext()) { - factory.COMPILED_VALUE_TYPE_ADAPTER.write(out, iterator.next()); - } - out.endArray(); - - out.endObject(); - } - - @Override - public DrawableValue.StateListValue read(JsonReader in) throws IOException { - - in.beginObject(); - - in.nextName(); - int[][] states = ProteusTypeAdapterFactory.readArrayOfIntArrays(in.nextString()); - - in.nextName(); - Value[] values = new Value[0]; - - in.beginArray(); - while (in.hasNext()) { - values = Arrays.copyOf(values, values.length + 1); - values[values.length - 1] = factory.COMPILED_VALUE_TYPE_ADAPTER.read(in); - } - in.endArray(); - - in.endObject(); - - return DrawableValue.StateListValue.valueOf(states, values); - } - }; - } - }; - - /** - * - */ - public final CustomValueTypeAdapterCreator DRAWABLE_URL = new CustomValueTypeAdapterCreator() { - @Override - public CustomValueTypeAdapter create(int type, ProteusTypeAdapterFactory factory) { - return new CustomValueTypeAdapter(type) { - @Override - public void write(JsonWriter out, DrawableValue.UrlValue value) throws IOException { - out.value(value.url); - } - - @Override - public DrawableValue.UrlValue read(JsonReader in) throws IOException { - return DrawableValue.UrlValue.valueOf(in.nextString()); - } - }; - } - }; - - /** - * - */ - public final CustomValueTypeAdapterCreator LAYOUT = new CustomValueTypeAdapterCreator() { - @Override - public CustomValueTypeAdapter create(int type, final ProteusTypeAdapterFactory factory) { - return new CustomValueTypeAdapter(type) { - - private static final String KEY_TYPE = "t"; - private static final String KEY_DATA = "d"; - private static final String KEY_ATTRIBUTES = "a"; - private static final String KEY_EXTRAS = "e"; - private static final String KEY_ATTRIBUTE_ID = "i"; - private static final String KEY_ATTRIBUTE_VALUE = "v"; - - @Override - public void write(JsonWriter out, Layout value) throws IOException { - out.beginObject(); - - out.name(KEY_TYPE); - out.value(value.type); - - if (null != value.data) { - out.name(KEY_DATA); - out.beginObject(); - for (Map.Entry entry : value.data.entrySet()) { - out.name(entry.getKey()); - factory.COMPILED_VALUE_TYPE_ADAPTER.write(out, entry.getValue()); - } - out.endObject(); - } - - - if (null != value.attributes) { - out.name(KEY_ATTRIBUTES); - out.beginArray(); - for (Layout.Attribute attribute : value.attributes) { - out.beginObject(); - - out.name(KEY_ATTRIBUTE_ID); - out.value(attribute.id); - - out.name(KEY_ATTRIBUTE_VALUE); - factory.COMPILED_VALUE_TYPE_ADAPTER.write(out, attribute.value); - - out.endObject(); - } - out.endArray(); - } - - if (null != value.extras) { - out.name(KEY_EXTRAS); - factory.COMPILED_VALUE_TYPE_ADAPTER.write(out, value.extras); - } - - out.endObject(); - } - - @Override - public Layout read(JsonReader in) throws IOException { - in.beginObject(); - - String name; - String type = null; - Map data = null; - List attributes = null; - ObjectValue extras = null; - - while (in.hasNext()) { - name = in.nextName(); - switch (name) { - case KEY_TYPE: - type = in.nextString(); - break; - case KEY_DATA: - data = readData(in); - break; - case KEY_ATTRIBUTES: - attributes = readAttributes(in); - break; - case KEY_EXTRAS: - extras = readExtras(in); - break; - default: - throw new IllegalStateException("Bad attribute '" + name + "'"); - } - } - - in.endObject(); - - if (null == type) { - throw new IllegalStateException("Layout must have type attribute!"); - } - - //noinspection ConstantConditions - return new Layout(type, attributes, data, extras); - } - - @Nullable - private Map readData(JsonReader in) throws IOException { - Map data = new HashMap<>(); - in.beginObject(); - String name; - Value value; - while (in.hasNext()) { - name = in.nextName(); - value = factory.COMPILED_VALUE_TYPE_ADAPTER.read(in); - data.put(name, value); - } - in.endObject(); - return data; - } - - @Nullable - private ObjectValue readExtras(JsonReader in) throws IOException { - return factory.COMPILED_VALUE_TYPE_ADAPTER.read(in).getAsObject(); - } - - @Nullable - private List readAttributes(JsonReader in) throws IOException { - List attributes = new ArrayList<>(); - - in.beginArray(); - int id; - Value value; - while (in.hasNext()) { - in.beginObject(); - in.nextName(); - id = Integer.parseInt(in.nextString()); - in.nextName(); - value = factory.COMPILED_VALUE_TYPE_ADAPTER.read(in); - attributes.add(new Layout.Attribute(id, value)); - in.endObject(); - } - in.endArray(); - - return attributes; - } - }; - } - }; - - /** - * - */ - public final CustomValueTypeAdapterCreator NESTED_BINDING = new CustomValueTypeAdapterCreator() { - @Override - public CustomValueTypeAdapter create(int type, final ProteusTypeAdapterFactory factory) { - return new CustomValueTypeAdapter(type) { - @Override - public void write(JsonWriter out, NestedBinding value) throws IOException { - factory.COMPILED_VALUE_TYPE_ADAPTER.write(out, value.getValue()); - } - - @Override - public NestedBinding read(JsonReader in) throws IOException { - return NestedBinding.valueOf(factory.COMPILED_VALUE_TYPE_ADAPTER.read(in)); - } - }; - } - }; - - /** - * - */ - public final CustomValueTypeAdapterCreator RESOURCE = new CustomValueTypeAdapterCreator() { - @Override - public CustomValueTypeAdapter create(int type, ProteusTypeAdapterFactory factory) { - return new CustomValueTypeAdapter(type) { - @Override - public void write(JsonWriter out, Resource value) throws IOException { - out.value(value.resId); - } - - @Override - public Resource read(JsonReader in) throws IOException { - return Resource.valueOf(Integer.parseInt(in.nextString())); - } - }; - } - }; - - /** - * - */ - public final CustomValueTypeAdapterCreator STYLE_RESOURCE = new CustomValueTypeAdapterCreator() { - @Override - public CustomValueTypeAdapter create(int type, ProteusTypeAdapterFactory factory) { - return new CustomValueTypeAdapter(type) { - - private static final String KEY_ATTRIBUTE_ID = "a"; - private static final String KEY_STYLE_ID = "s"; - - @Override - public void write(JsonWriter out, StyleResource value) throws IOException { - out.beginObject(); - - out.name(KEY_ATTRIBUTE_ID); - out.value(value.attributeId); - - out.name(KEY_STYLE_ID); - out.value(value.styleId); - - out.endObject(); - } - - @Override - public StyleResource read(JsonReader in) throws IOException { - in.beginObject(); - in.nextName(); - String attributeId = in.nextString(); - in.nextName(); - String styleId = in.nextString(); - in.endObject(); - return StyleResource.valueOf(Integer.parseInt(styleId), Integer.parseInt(attributeId)); - } - }; - } - }; - - private DefaultModule() { + @Override + public NestedBinding read(JsonReader in) throws IOException { + return NestedBinding.valueOf(factory.COMPILED_VALUE_TYPE_ADAPTER.read(in)); + } + }; } + }; - public static DefaultModule create() { - return new DefaultModule(); + /** + * + */ + public final CustomValueTypeAdapterCreator RESOURCE = new CustomValueTypeAdapterCreator() { + @Override + public CustomValueTypeAdapter create(int type, ProteusTypeAdapterFactory factory) { + return new CustomValueTypeAdapter(type) { + @Override + public void write(JsonWriter out, Resource value) throws IOException { + out.value(value.resId); + } + + @Override + public Resource read(JsonReader in) throws IOException { + return Resource.valueOf(Integer.parseInt(in.nextString())); + } + }; } + }; + /** + * + */ + public final CustomValueTypeAdapterCreator STYLE_RESOURCE = new CustomValueTypeAdapterCreator() { @Override - public void register(ProteusTypeAdapterFactory factory) { - factory.register(AttributeResource.class, ATTRIBUTE_RESOURCE); - factory.register(Binding.class, BINDING); - factory.register(Color.Int.class, COLOR_INT); - factory.register(Color.StateList.class, COLOR_STATE_LIST); - factory.register(Dimension.class, DIMENSION); + public CustomValueTypeAdapter create(int type, ProteusTypeAdapterFactory factory) { + return new CustomValueTypeAdapter(type) { + + private static final String KEY_ATTRIBUTE_ID = "a"; + private static final String KEY_STYLE_ID = "s"; + + @Override + public void write(JsonWriter out, StyleResource value) throws IOException { + out.beginObject(); + + out.name(KEY_ATTRIBUTE_ID); + out.value(value.attributeId); + + out.name(KEY_STYLE_ID); + out.value(value.styleId); + + out.endObject(); + } + + @Override + public StyleResource read(JsonReader in) throws IOException { + in.beginObject(); + in.nextName(); + String attributeId = in.nextString(); + in.nextName(); + String styleId = in.nextString(); + in.endObject(); + return StyleResource.valueOf(Integer.parseInt(styleId), Integer.parseInt(attributeId)); + } + }; + } + }; + + private DefaultModule() { + } + + public static DefaultModule create() { + return new DefaultModule(); + } + + @Override + public void register(ProteusTypeAdapterFactory factory) { + factory.register(AttributeResource.class, ATTRIBUTE_RESOURCE); + factory.register(Binding.class, BINDING); + factory.register(Color.Int.class, COLOR_INT); + factory.register(Color.StateList.class, COLOR_STATE_LIST); + factory.register(Dimension.class, DIMENSION); /*factory.register(DrawableValue.Gradient.class, DRAWABLE_VALUE); factory.register(DrawableValue.Corners.class, DRAWABLE_VALUE); @@ -746,18 +746,18 @@ public void register(ProteusTypeAdapterFactory factory) { factory.register(DrawableValue.Size.class, DRAWABLE_VALUE); factory.register(DrawableValue.Stroke.class, DRAWABLE_VALUE);*/ - factory.register(DrawableValue.ColorValue.class, DRAWABLE_COLOR); - factory.register(DrawableValue.LayerListValue.class, DRAWABLE_LAYER_LIST); - factory.register(DrawableValue.LevelListValue.class, DRAWABLE_LEVEL_LIST); - factory.register(DrawableValue.RippleValue.class, DRAWABLE_RIPPLE); - factory.register(DrawableValue.ShapeValue.class, DRAWABLE_SHAPE); - factory.register(DrawableValue.StateListValue.class, DRAWABLE_STATE_LIST); - factory.register(DrawableValue.UrlValue.class, DRAWABLE_URL); - - factory.register(Layout.class, LAYOUT); - factory.register(NestedBinding.class, NESTED_BINDING); - factory.register(Resource.class, RESOURCE); - factory.register(StyleResource.class, STYLE_RESOURCE); - } + factory.register(DrawableValue.ColorValue.class, DRAWABLE_COLOR); + factory.register(DrawableValue.LayerListValue.class, DRAWABLE_LAYER_LIST); + factory.register(DrawableValue.LevelListValue.class, DRAWABLE_LEVEL_LIST); + factory.register(DrawableValue.RippleValue.class, DRAWABLE_RIPPLE); + factory.register(DrawableValue.ShapeValue.class, DRAWABLE_SHAPE); + factory.register(DrawableValue.StateListValue.class, DRAWABLE_STATE_LIST); + factory.register(DrawableValue.UrlValue.class, DRAWABLE_URL); + + factory.register(Layout.class, LAYOUT); + factory.register(NestedBinding.class, NESTED_BINDING); + factory.register(Resource.class, RESOURCE); + factory.register(StyleResource.class, STYLE_RESOURCE); + } } diff --git a/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/ProteusTypeAdapterFactory.java b/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/ProteusTypeAdapterFactory.java index 98cb68ae..8595fd79 100644 --- a/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/ProteusTypeAdapterFactory.java +++ b/gson-adapter/src/main/java/com/flipkart/android/proteus/gson/ProteusTypeAdapterFactory.java @@ -58,491 +58,491 @@ */ public class ProteusTypeAdapterFactory implements TypeAdapterFactory { - public static final ProteusInstanceHolder PROTEUS_INSTANCE_HOLDER = new ProteusInstanceHolder(); + public static final ProteusInstanceHolder PROTEUS_INSTANCE_HOLDER = new ProteusInstanceHolder(); - Context context; + Context context; - /** - * - */ - public final TypeAdapter VALUE_TYPE_ADAPTER = new TypeAdapter() { - @Override - public void write(JsonWriter out, Value value) throws IOException { - throw new UnsupportedOperationException("Use ProteusTypeAdapterFactory.COMPILED_VALUE_TYPE_ADAPTER instead"); - } + /** + * + */ + public final TypeAdapter VALUE_TYPE_ADAPTER = new TypeAdapter() { + @Override + public void write(JsonWriter out, Value value) throws IOException { + throw new UnsupportedOperationException("Use ProteusTypeAdapterFactory.COMPILED_VALUE_TYPE_ADAPTER instead"); + } - @Override - public Value read(JsonReader in) throws IOException { - switch (in.peek()) { - case STRING: - return compileString(getContext(), in.nextString()); - case NUMBER: - String number = in.nextString(); - return new Primitive(new LazilyParsedNumber(number)); - case BOOLEAN: - return new Primitive(in.nextBoolean()); - case NULL: - in.nextNull(); - return Null.INSTANCE; - case BEGIN_ARRAY: - Array array = new Array(); - in.beginArray(); - while (in.hasNext()) { - array.add(read(in)); - } - in.endArray(); - return array; - case BEGIN_OBJECT: - ObjectValue object = new ObjectValue(); - in.beginObject(); - if (in.hasNext()) { - String name = in.nextName(); - if (ProteusConstants.TYPE.equals(name) && JsonToken.STRING.equals(in.peek())) { - String type = in.nextString(); - if (PROTEUS_INSTANCE_HOLDER.isLayout(type)) { - Layout layout = LAYOUT_TYPE_ADAPTER.read(type, PROTEUS_INSTANCE_HOLDER.getProteus(), in); - in.endObject(); - return layout; - } else { - object.add(name, compileString(getContext(), type)); - } - } else { - object.add(name, read(in)); - } - } - while (in.hasNext()) { - object.add(in.nextName(), read(in)); - } - in.endObject(); - return object; - case END_DOCUMENT: - case NAME: - case END_OBJECT: - case END_ARRAY: - default: - throw new IllegalArgumentException(); + @Override + public Value read(JsonReader in) throws IOException { + switch (in.peek()) { + case STRING: + return compileString(getContext(), in.nextString()); + case NUMBER: + String number = in.nextString(); + return new Primitive(new LazilyParsedNumber(number)); + case BOOLEAN: + return new Primitive(in.nextBoolean()); + case NULL: + in.nextNull(); + return Null.INSTANCE; + case BEGIN_ARRAY: + Array array = new Array(); + in.beginArray(); + while (in.hasNext()) { + array.add(read(in)); + } + in.endArray(); + return array; + case BEGIN_OBJECT: + ObjectValue object = new ObjectValue(); + in.beginObject(); + if (in.hasNext()) { + String name = in.nextName(); + if (ProteusConstants.TYPE.equals(name) && JsonToken.STRING.equals(in.peek())) { + String type = in.nextString(); + if (PROTEUS_INSTANCE_HOLDER.isLayout(type)) { + Layout layout = LAYOUT_TYPE_ADAPTER.read(type, PROTEUS_INSTANCE_HOLDER.getProteus(), in); + in.endObject(); + return layout; + } else { + object.add(name, compileString(getContext(), type)); + } + } else { + object.add(name, read(in)); } - } - }.nullSafe(); - - /** - * - */ - public final TypeAdapter PRIMITIVE_TYPE_ADAPTER = new TypeAdapter() { - - @Override - public void write(JsonWriter out, Primitive value) throws IOException { - VALUE_TYPE_ADAPTER.write(out, value); - } - - @Override - public Primitive read(JsonReader in) throws IOException { - Value value = VALUE_TYPE_ADAPTER.read(in); - return value != null && value.isPrimitive() ? value.getAsPrimitive() : null; - } - }.nullSafe(); + } + while (in.hasNext()) { + object.add(in.nextName(), read(in)); + } + in.endObject(); + return object; + case END_DOCUMENT: + case NAME: + case END_OBJECT: + case END_ARRAY: + default: + throw new IllegalArgumentException(); + } + } + }.nullSafe(); - /** - * - */ - public final TypeAdapter OBJECT_TYPE_ADAPTER = new TypeAdapter() { - @Override - public void write(JsonWriter out, ObjectValue value) throws IOException { - VALUE_TYPE_ADAPTER.write(out, value); - } + /** + * + */ + public final TypeAdapter PRIMITIVE_TYPE_ADAPTER = new TypeAdapter() { - @Override - public ObjectValue read(JsonReader in) throws IOException { - Value value = VALUE_TYPE_ADAPTER.read(in); - return value != null && value.isObject() ? value.getAsObject() : null; - } - }.nullSafe(); + @Override + public void write(JsonWriter out, Primitive value) throws IOException { + VALUE_TYPE_ADAPTER.write(out, value); + } - /** - * - */ - public final TypeAdapter ARRAY_TYPE_ADAPTER = new TypeAdapter() { - @Override - public void write(JsonWriter out, Array value) throws IOException { - VALUE_TYPE_ADAPTER.write(out, value); - } + @Override + public Primitive read(JsonReader in) throws IOException { + Value value = VALUE_TYPE_ADAPTER.read(in); + return value != null && value.isPrimitive() ? value.getAsPrimitive() : null; + } + }.nullSafe(); - @Override - public Array read(JsonReader in) throws IOException { - Value value = VALUE_TYPE_ADAPTER.read(in); - return value != null && value.isArray() ? value.getAsArray() : null; - } - }.nullSafe(); + /** + * + */ + public final TypeAdapter OBJECT_TYPE_ADAPTER = new TypeAdapter() { + @Override + public void write(JsonWriter out, ObjectValue value) throws IOException { + VALUE_TYPE_ADAPTER.write(out, value); + } - /** - * - */ - public final TypeAdapter NULL_TYPE_ADAPTER = new TypeAdapter() { + @Override + public ObjectValue read(JsonReader in) throws IOException { + Value value = VALUE_TYPE_ADAPTER.read(in); + return value != null && value.isObject() ? value.getAsObject() : null; + } + }.nullSafe(); - @Override - public void write(JsonWriter out, Null value) throws IOException { - VALUE_TYPE_ADAPTER.write(out, value); - } + /** + * + */ + public final TypeAdapter ARRAY_TYPE_ADAPTER = new TypeAdapter() { + @Override + public void write(JsonWriter out, Array value) throws IOException { + VALUE_TYPE_ADAPTER.write(out, value); + } - @Override - public Null read(JsonReader in) throws IOException { - Value value = VALUE_TYPE_ADAPTER.read(in); - return value != null && value.isNull() ? value.getAsNull() : null; - } - }.nullSafe(); + @Override + public Array read(JsonReader in) throws IOException { + Value value = VALUE_TYPE_ADAPTER.read(in); + return value != null && value.isArray() ? value.getAsArray() : null; + } + }.nullSafe(); - /** - * - */ - public final LayoutTypeAdapter LAYOUT_TYPE_ADAPTER = new LayoutTypeAdapter(); + /** + * + */ + public final TypeAdapter NULL_TYPE_ADAPTER = new TypeAdapter() { - /** - * - */ - public final TypeAdapter COMPILED_VALUE_TYPE_ADAPTER = new TypeAdapter() { - - public static final String TYPE = "$t"; - public static final String VALUE = "$v"; - - @Override - public void write(JsonWriter out, Value value) throws IOException { - if (value == null || value.isNull()) { - out.nullValue(); - } else if (value.isPrimitive()) { - Primitive primitive = value.getAsPrimitive(); - if (primitive.isNumber()) { - out.value(primitive.getAsNumber()); - } else if (primitive.isBoolean()) { - out.value(primitive.getAsBoolean()); - } else { - out.value(primitive.getAsString()); - } - } else if (value.isObject()) { - out.beginObject(); - for (Map.Entry e : value.getAsObject().entrySet()) { - out.name(e.getKey()); - write(out, e.getValue()); - } - out.endObject(); - } else if (value.isArray()) { - out.beginArray(); - Iterator iterator = value.getAsArray().iterator(); - while (iterator.hasNext()) { - write(out, iterator.next()); - } - out.endArray(); - } else { - CustomValueTypeAdapter adapter = getCustomValueTypeAdapter(value.getClass()); + @Override + public void write(JsonWriter out, Null value) throws IOException { + VALUE_TYPE_ADAPTER.write(out, value); + } - out.beginObject(); + @Override + public Null read(JsonReader in) throws IOException { + Value value = VALUE_TYPE_ADAPTER.read(in); + return value != null && value.isNull() ? value.getAsNull() : null; + } + }.nullSafe(); - out.name(TYPE); - out.value(adapter.type); + /** + * + */ + public final LayoutTypeAdapter LAYOUT_TYPE_ADAPTER = new LayoutTypeAdapter(); - out.name(VALUE); + /** + * + */ + public final TypeAdapter COMPILED_VALUE_TYPE_ADAPTER = new TypeAdapter() { - //noinspection unchecked - adapter.write(out, value); + public static final String TYPE = "$t"; + public static final String VALUE = "$v"; - out.endObject(); - } + @Override + public void write(JsonWriter out, Value value) throws IOException { + if (value == null || value.isNull()) { + out.nullValue(); + } else if (value.isPrimitive()) { + Primitive primitive = value.getAsPrimitive(); + if (primitive.isNumber()) { + out.value(primitive.getAsNumber()); + } else if (primitive.isBoolean()) { + out.value(primitive.getAsBoolean()); + } else { + out.value(primitive.getAsString()); } - - @Override - public Value read(JsonReader in) throws IOException { - switch (in.peek()) { - case STRING: - return compileString(getContext(), in.nextString()); - case NUMBER: - String number = in.nextString(); - return new Primitive(new LazilyParsedNumber(number)); - case BOOLEAN: - return new Primitive(in.nextBoolean()); - case NULL: - in.nextNull(); - return Null.INSTANCE; - case BEGIN_ARRAY: - Array array = new Array(); - in.beginArray(); - while (in.hasNext()) { - array.add(read(in)); - } - in.endArray(); - return array; - case BEGIN_OBJECT: - ObjectValue object = new ObjectValue(); - in.beginObject(); - if (in.hasNext()) { - String name = in.nextName(); - if (TYPE.equals(name) && JsonToken.NUMBER.equals(in.peek())) { - int type = Integer.parseInt(in.nextString()); - CustomValueTypeAdapter adapter = getCustomValueTypeAdapter(type); - in.nextName(); - Value value = adapter.read(in); - in.endObject(); - return value; - } else { - object.add(name, read(in)); - } - } - while (in.hasNext()) { - object.add(in.nextName(), read(in)); - } - in.endObject(); - return object; - case END_DOCUMENT: - case NAME: - case END_OBJECT: - case END_ARRAY: - default: - throw new IllegalArgumentException(); - } + } else if (value.isObject()) { + out.beginObject(); + for (Map.Entry e : value.getAsObject().entrySet()) { + out.name(e.getKey()); + write(out, e.getValue()); + } + out.endObject(); + } else if (value.isArray()) { + out.beginArray(); + Iterator iterator = value.getAsArray().iterator(); + while (iterator.hasNext()) { + write(out, iterator.next()); } + out.endArray(); + } else { + CustomValueTypeAdapter adapter = getCustomValueTypeAdapter(value.getClass()); - }; + out.beginObject(); + out.name(TYPE); + out.value(adapter.type); - /** - * - */ - private CustomValueTypeAdapterMap map = new CustomValueTypeAdapterMap(); + out.name(VALUE); - public static final String ARRAYS_DELIMITER = "|"; - public static final String ARRAY_DELIMITER = ","; + //noinspection unchecked + adapter.write(out, value); - public static String writeArrayOfInts(int[] array) { - StringBuilder builder = new StringBuilder(); - for (int index = 0; index < array.length; index++) { - builder.append(array[index]); - if (index < array.length - 1) { - builder.append(ARRAY_DELIMITER); - } - } - return builder.toString(); + out.endObject(); + } } - public static String writeArrayOfIntArrays(int[][] arrays) { - StringBuilder builder = new StringBuilder(); - for (int index = 0; index < arrays.length; index++) { - builder.append(writeArrayOfInts(arrays[index])); - if (index < arrays.length - 1) { - builder.append(ARRAYS_DELIMITER); + @Override + public Value read(JsonReader in) throws IOException { + switch (in.peek()) { + case STRING: + return compileString(getContext(), in.nextString()); + case NUMBER: + String number = in.nextString(); + return new Primitive(new LazilyParsedNumber(number)); + case BOOLEAN: + return new Primitive(in.nextBoolean()); + case NULL: + in.nextNull(); + return Null.INSTANCE; + case BEGIN_ARRAY: + Array array = new Array(); + in.beginArray(); + while (in.hasNext()) { + array.add(read(in)); + } + in.endArray(); + return array; + case BEGIN_OBJECT: + ObjectValue object = new ObjectValue(); + in.beginObject(); + if (in.hasNext()) { + String name = in.nextName(); + if (TYPE.equals(name) && JsonToken.NUMBER.equals(in.peek())) { + int type = Integer.parseInt(in.nextString()); + CustomValueTypeAdapter adapter = getCustomValueTypeAdapter(type); + in.nextName(); + Value value = adapter.read(in); + in.endObject(); + return value; + } else { + object.add(name, read(in)); } - } - return builder.toString(); + } + while (in.hasNext()) { + object.add(in.nextName(), read(in)); + } + in.endObject(); + return object; + case END_DOCUMENT: + case NAME: + case END_OBJECT: + case END_ARRAY: + default: + throw new IllegalArgumentException(); + } } - public static int[] readArrayOfInts(String string) { - int[] array = new int[0]; - StringTokenizer tokenizer = new StringTokenizer(string, ARRAY_DELIMITER); - while (tokenizer.hasMoreTokens()) { - array = Arrays.copyOf(array, array.length + 1); - array[array.length - 1] = Integer.parseInt(tokenizer.nextToken()); - } - return array; - } + }; - public static int[][] readArrayOfIntArrays(String string) { - int[][] arrays = new int[0][]; - StringTokenizer tokenizer = new StringTokenizer(string, ARRAYS_DELIMITER); - while (tokenizer.hasMoreTokens()) { - arrays = Arrays.copyOf(arrays, arrays.length + 1); - arrays[arrays.length - 1] = readArrayOfInts(tokenizer.nextToken()); - } - return arrays; - } - /** - * @param context - */ - public ProteusTypeAdapterFactory(Context context) { - this.context = context; - DefaultModule.create().register(this); - } + /** + * + */ + private CustomValueTypeAdapterMap map = new CustomValueTypeAdapterMap(); - @Override - public TypeAdapter create(Gson gson, TypeToken type) { - Class clazz = type.getRawType(); - - if (clazz == Primitive.class) { - //noinspection unchecked - return (TypeAdapter) PRIMITIVE_TYPE_ADAPTER; - } else if (clazz == ObjectValue.class) { - //noinspection unchecked - return (TypeAdapter) OBJECT_TYPE_ADAPTER; - } else if (clazz == Array.class) { - //noinspection unchecked - return (TypeAdapter) ARRAY_TYPE_ADAPTER; - } else if (clazz == Null.class) { - //noinspection unchecked - return (TypeAdapter) NULL_TYPE_ADAPTER; - } else if (clazz == Layout.class) { - //noinspection unchecked - return (TypeAdapter) LAYOUT_TYPE_ADAPTER; - } else if (clazz == Value.class) { - //noinspection unchecked - return (TypeAdapter) VALUE_TYPE_ADAPTER; - } + public static final String ARRAYS_DELIMITER = "|"; + public static final String ARRAY_DELIMITER = ","; - return null; + public static String writeArrayOfInts(int[] array) { + StringBuilder builder = new StringBuilder(); + for (int index = 0; index < array.length; index++) { + builder.append(array[index]); + if (index < array.length - 1) { + builder.append(ARRAY_DELIMITER); + } } - - public void register(Class clazz, CustomValueTypeAdapterCreator creator) { - map.register(clazz, creator); + return builder.toString(); + } + + public static String writeArrayOfIntArrays(int[][] arrays) { + StringBuilder builder = new StringBuilder(); + for (int index = 0; index < arrays.length; index++) { + builder.append(writeArrayOfInts(arrays[index])); + if (index < arrays.length - 1) { + builder.append(ARRAYS_DELIMITER); + } } - - public CustomValueTypeAdapter getCustomValueTypeAdapter(Class clazz) { - return map.get(clazz); + return builder.toString(); + } + + public static int[] readArrayOfInts(String string) { + int[] array = new int[0]; + StringTokenizer tokenizer = new StringTokenizer(string, ARRAY_DELIMITER); + while (tokenizer.hasMoreTokens()) { + array = Arrays.copyOf(array, array.length + 1); + array[array.length - 1] = Integer.parseInt(tokenizer.nextToken()); } - - public CustomValueTypeAdapter getCustomValueTypeAdapter(int type) { - return map.get(type); + return array; + } + + public static int[][] readArrayOfIntArrays(String string) { + int[][] arrays = new int[0][]; + StringTokenizer tokenizer = new StringTokenizer(string, ARRAYS_DELIMITER); + while (tokenizer.hasMoreTokens()) { + arrays = Arrays.copyOf(arrays, arrays.length + 1); + arrays[arrays.length - 1] = readArrayOfInts(tokenizer.nextToken()); } - - public Context getContext() { - return context; + return arrays; + } + + /** + * @param context + */ + public ProteusTypeAdapterFactory(Context context) { + this.context = context; + DefaultModule.create().register(this); + } + + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + Class clazz = type.getRawType(); + + if (clazz == Primitive.class) { + //noinspection unchecked + return (TypeAdapter) PRIMITIVE_TYPE_ADAPTER; + } else if (clazz == ObjectValue.class) { + //noinspection unchecked + return (TypeAdapter) OBJECT_TYPE_ADAPTER; + } else if (clazz == Array.class) { + //noinspection unchecked + return (TypeAdapter) ARRAY_TYPE_ADAPTER; + } else if (clazz == Null.class) { + //noinspection unchecked + return (TypeAdapter) NULL_TYPE_ADAPTER; + } else if (clazz == Layout.class) { + //noinspection unchecked + return (TypeAdapter) LAYOUT_TYPE_ADAPTER; + } else if (clazz == Value.class) { + //noinspection unchecked + return (TypeAdapter) VALUE_TYPE_ADAPTER; } - static Value compileString(Context context, String string) { - if (Binding.isBindingValue(string)) { - return Binding.valueOf(string, context, PROTEUS_INSTANCE_HOLDER.getProteus().functions); - } else { - return new Primitive(string); - } - } + return null; + } + + public void register(Class clazz, CustomValueTypeAdapterCreator creator) { + map.register(clazz, creator); + } + + public CustomValueTypeAdapter getCustomValueTypeAdapter(Class clazz) { + return map.get(clazz); + } - public interface Module { + public CustomValueTypeAdapter getCustomValueTypeAdapter(int type) { + return map.get(type); + } - /** - * @param factory - */ - void register(ProteusTypeAdapterFactory factory); + public Context getContext() { + return context; + } + static Value compileString(Context context, String string) { + if (Binding.isBindingValue(string)) { + return Binding.valueOf(string, context, PROTEUS_INSTANCE_HOLDER.getProteus().functions); + } else { + return new Primitive(string); } + } - public static class ProteusInstanceHolder { + public interface Module { - private Proteus proteus; + /** + * @param factory + */ + void register(ProteusTypeAdapterFactory factory); - ProteusInstanceHolder() { - } + } - public Proteus getProteus() { - return proteus; - } + public static class ProteusInstanceHolder { - public void setProteus(Proteus proteus) { - this.proteus = proteus; - } + private Proteus proteus; - public boolean isLayout(String type) { - return null != proteus && proteus.has(type); - } + ProteusInstanceHolder() { } - public class LayoutTypeAdapter extends TypeAdapter { + public Proteus getProteus() { + return proteus; + } - @Override - public void write(JsonWriter out, Layout value) throws IOException { - VALUE_TYPE_ADAPTER.write(out, value); - } + public void setProteus(Proteus proteus) { + this.proteus = proteus; + } - @Override - public Layout read(JsonReader in) throws IOException { - Value value = VALUE_TYPE_ADAPTER.read(in); - return value != null && value.isLayout() ? value.getAsLayout() : null; - } + public boolean isLayout(String type) { + return null != proteus && proteus.has(type); + } + } - public Layout read(String type, Proteus proteus, JsonReader in) throws IOException { - List attributes = new ArrayList<>(); - Map data = null; - ObjectValue extras = new ObjectValue(); - String name; - while (in.hasNext()) { - name = in.nextName(); - if (ProteusConstants.DATA.equals(name)) { - data = readData(in); - } else { - ViewTypeParser.AttributeSet.Attribute attribute = proteus.getAttributeId(name, type); - if (null != attribute) { - FunctionManager manager = PROTEUS_INSTANCE_HOLDER.getProteus().functions; - Value value = attribute.processor.precompile(VALUE_TYPE_ADAPTER.read(in), getContext(), manager); - attributes.add(new Layout.Attribute(attribute.id, value)); - } else { - extras.add(name, VALUE_TYPE_ADAPTER.read(in)); - } - } - } - return new Layout(type, attributes.size() > 0 ? attributes : null, data, extras.entrySet().size() > 0 ? extras : null); - } + public class LayoutTypeAdapter extends TypeAdapter { - public Map readData(JsonReader in) throws IOException { - JsonToken peek = in.peek(); - if (peek == JsonToken.NULL) { - in.nextNull(); - return new HashMap<>(); - } + @Override + public void write(JsonWriter out, Layout value) throws IOException { + VALUE_TYPE_ADAPTER.write(out, value); + } - if (peek != JsonToken.BEGIN_OBJECT) { - throw new JsonSyntaxException("data must be a Map."); - } + @Override + public Layout read(JsonReader in) throws IOException { + Value value = VALUE_TYPE_ADAPTER.read(in); + return value != null && value.isLayout() ? value.getAsLayout() : null; + } - Map data = new LinkedHashMap<>(); - - in.beginObject(); - while (in.hasNext()) { - JsonReaderInternalAccess.INSTANCE.promoteNameToValue(in); - String key = in.nextString(); - Value value = VALUE_TYPE_ADAPTER.read(in); - Value compiled = AttributeProcessor.staticPreCompile(value, context, PROTEUS_INSTANCE_HOLDER.getProteus().functions); - if (compiled != null) { - value = compiled; - } - Value replaced = data.put(key, value); - if (replaced != null) { - throw new JsonSyntaxException("duplicate key: " + key); - } - } - in.endObject(); + public Layout read(String type, Proteus proteus, JsonReader in) throws IOException { + List attributes = new ArrayList<>(); + Map data = null; + ObjectValue extras = new ObjectValue(); + String name; + while (in.hasNext()) { + name = in.nextName(); + if (ProteusConstants.DATA.equals(name)) { + data = readData(in); + } else { + ViewTypeParser.AttributeSet.Attribute attribute = proteus.getAttributeId(name, type); + if (null != attribute) { + FunctionManager manager = PROTEUS_INSTANCE_HOLDER.getProteus().functions; + Value value = attribute.processor.precompile(VALUE_TYPE_ADAPTER.read(in), getContext(), manager); + attributes.add(new Layout.Attribute(attribute.id, value)); + } else { + extras.add(name, VALUE_TYPE_ADAPTER.read(in)); + } + } + } + return new Layout(type, attributes.size() > 0 ? attributes : null, data, extras.entrySet().size() > 0 ? extras : null); + } - return data; + public Map readData(JsonReader in) throws IOException { + JsonToken peek = in.peek(); + if (peek == JsonToken.NULL) { + in.nextNull(); + return new HashMap<>(); + } + + if (peek != JsonToken.BEGIN_OBJECT) { + throw new JsonSyntaxException("data must be a Map."); + } + + Map data = new LinkedHashMap<>(); + + in.beginObject(); + while (in.hasNext()) { + JsonReaderInternalAccess.INSTANCE.promoteNameToValue(in); + String key = in.nextString(); + Value value = VALUE_TYPE_ADAPTER.read(in); + Value compiled = AttributeProcessor.staticPreCompile(value, context, PROTEUS_INSTANCE_HOLDER.getProteus().functions); + if (compiled != null) { + value = compiled; } + Value replaced = data.put(key, value); + if (replaced != null) { + throw new JsonSyntaxException("duplicate key: " + key); + } + } + in.endObject(); + + return data; } + } - private class CustomValueTypeAdapterMap { + private class CustomValueTypeAdapterMap { - private final Map, CustomValueTypeAdapter> types = new HashMap<>(); + private final Map, CustomValueTypeAdapter> types = new HashMap<>(); - private CustomValueTypeAdapter[] adapters = new CustomValueTypeAdapter[0]; + private CustomValueTypeAdapter[] adapters = new CustomValueTypeAdapter[0]; - CustomValueTypeAdapterMap() { - } + CustomValueTypeAdapterMap() { + } - public CustomValueTypeAdapter register(Class clazz, CustomValueTypeAdapterCreator creator) { - CustomValueTypeAdapter adapter = types.get(clazz); - if (null != adapter) { - return adapter; - } - //noinspection unchecked - adapter = creator.create(adapters.length, ProteusTypeAdapterFactory.this); - adapters = Arrays.copyOf(adapters, adapters.length + 1); - adapters[adapters.length - 1] = adapter; - return types.put(clazz, adapter); - } + public CustomValueTypeAdapter register(Class clazz, CustomValueTypeAdapterCreator creator) { + CustomValueTypeAdapter adapter = types.get(clazz); + if (null != adapter) { + return adapter; + } + //noinspection unchecked + adapter = creator.create(adapters.length, ProteusTypeAdapterFactory.this); + adapters = Arrays.copyOf(adapters, adapters.length + 1); + adapters[adapters.length - 1] = adapter; + return types.put(clazz, adapter); + } - public CustomValueTypeAdapter get(Class clazz) { - CustomValueTypeAdapter i = types.get(clazz); - if (null == i) { - throw new IllegalArgumentException(clazz.getName() + " is not a known value type! Remember to register the class first"); - } - return types.get(clazz); - } + public CustomValueTypeAdapter get(Class clazz) { + CustomValueTypeAdapter i = types.get(clazz); + if (null == i) { + throw new IllegalArgumentException(clazz.getName() + " is not a known value type! Remember to register the class first"); + } + return types.get(clazz); + } - public CustomValueTypeAdapter get(int i) { - if (i < adapters.length) { - return adapters[i]; - } - throw new IllegalArgumentException(i + " is not a known value type! Did you conjure up this int?"); - } + public CustomValueTypeAdapter get(int i) { + if (i < adapters.length) { + return adapters[i]; + } + throw new IllegalArgumentException(i + " is not a known value type! Did you conjure up this int?"); } + } } diff --git a/gson-adapter/src/test/java/com/flipkart/android/proteus/gson/ProteusTypeAdapterFactoryTest.java b/gson-adapter/src/test/java/com/flipkart/android/proteus/gson/ProteusTypeAdapterFactoryTest.java index 7623290b..35dc7a11 100644 --- a/gson-adapter/src/test/java/com/flipkart/android/proteus/gson/ProteusTypeAdapterFactoryTest.java +++ b/gson-adapter/src/test/java/com/flipkart/android/proteus/gson/ProteusTypeAdapterFactoryTest.java @@ -43,65 +43,65 @@ */ public class ProteusTypeAdapterFactoryTest { - @Mock - Context context = mock(Context.class); - - private TypeAdapter adapter; - private Proteus proteus; - - @Before - public void before() { - ProteusTypeAdapterFactory factory = new ProteusTypeAdapterFactory(context); - proteus = new ProteusBuilder().build(); - ProteusTypeAdapterFactory.PROTEUS_INSTANCE_HOLDER.setProteus(proteus); - adapter = factory.COMPILED_VALUE_TYPE_ADAPTER; - } - - @Test - public void primitive() throws IOException { - Primitive in = new Primitive("this is a string"); - String json = adapter.toJson(in); - Value out = adapter.fromJson(json); - assertThat(in, is(out)); - } - - @Test - public void object() throws IOException { - - ObjectValue in = new ObjectValue(); - in.add("a", new Primitive(1)); - in.add("b", new Primitive(2)); - //in.add("c", new Array(new Value[]{new Primitive(3), Color.valueOf("#545454")})); - - ObjectValue nested = new ObjectValue(); - //nested.add("d", AttributeResource.valueOf(123)); - //nested.add("e", Binding.valueOf("@{a.b.c}", proteus.functions)); - //nested.add("f", Binding.valueOf("@{x.y.z}${number()}", proteus.functions)); - //nested.add("g", Binding.valueOf("date is @{a.b.c}${date('E, MM yyyy')}", proteus.functions)); - in.add("z", nested); - - String json = adapter.toJson(in); - - Value out = adapter.fromJson(json); - - assertThat(1, is(1)); - } - - @Test - public void color_state_list() throws IOException { - int[][] states = new int[][]{ - new int[]{1, 2, 3}, - new int[]{4, 5, 6} - }; - int[] colors = new int[]{7, 8, 9}; - - Value in = Color.StateList.valueOf(states, colors); - - String json = adapter.toJson(in); - - Value out = adapter.fromJson(json); - - assertThat(1, is(1)); - } + @Mock + Context context = mock(Context.class); + + private TypeAdapter adapter; + private Proteus proteus; + + @Before + public void before() { + ProteusTypeAdapterFactory factory = new ProteusTypeAdapterFactory(context); + proteus = new ProteusBuilder().build(); + ProteusTypeAdapterFactory.PROTEUS_INSTANCE_HOLDER.setProteus(proteus); + adapter = factory.COMPILED_VALUE_TYPE_ADAPTER; + } + + @Test + public void primitive() throws IOException { + Primitive in = new Primitive("this is a string"); + String json = adapter.toJson(in); + Value out = adapter.fromJson(json); + assertThat(in, is(out)); + } + + @Test + public void object() throws IOException { + + ObjectValue in = new ObjectValue(); + in.add("a", new Primitive(1)); + in.add("b", new Primitive(2)); + //in.add("c", new Array(new Value[]{new Primitive(3), Color.valueOf("#545454")})); + + ObjectValue nested = new ObjectValue(); + //nested.add("d", AttributeResource.valueOf(123)); + //nested.add("e", Binding.valueOf("@{a.b.c}", proteus.functions)); + //nested.add("f", Binding.valueOf("@{x.y.z}${number()}", proteus.functions)); + //nested.add("g", Binding.valueOf("date is @{a.b.c}${date('E, MM yyyy')}", proteus.functions)); + in.add("z", nested); + + String json = adapter.toJson(in); + + Value out = adapter.fromJson(json); + + assertThat(1, is(1)); + } + + @Test + public void color_state_list() throws IOException { + int[][] states = new int[][]{ + new int[]{1, 2, 3}, + new int[]{4, 5, 6} + }; + int[] colors = new int[]{7, 8, 9}; + + Value in = Color.StateList.valueOf(states, colors); + + String json = adapter.toJson(in); + + Value out = adapter.fromJson(json); + + assertThat(1, is(1)); + } } \ No newline at end of file From 3bcb19e519e1ca15a8d58662f13cf7537aa2c240 Mon Sep 17 00:00:00 2001 From: Aditya Sharat Date: Sun, 13 Jan 2019 00:47:51 +0000 Subject: [PATCH 17/19] reformat code --- proteus-core/AndroidManifest.xml | 5 +- .../res/layout/layout_params_hack.xml | 4 +- proteus-core/res/values/values.xml | 5 +- .../android/proteus/BoundAttribute.java | 26 +- .../flipkart/android/proteus/DataContext.java | 326 ++-- .../flipkart/android/proteus/Function.java | 1198 ++++++------- .../android/proteus/FunctionManager.java | 24 +- .../flipkart/android/proteus/IdGenerator.java | 18 +- .../android/proteus/LayoutManager.java | 12 +- .../com/flipkart/android/proteus/Proteus.java | 106 +- .../android/proteus/ProteusBuilder.java | 276 +-- .../android/proteus/ProteusConstants.java | 34 +- .../android/proteus/ProteusContext.java | 222 +-- .../proteus/ProteusContextWrapper.java | 6 +- .../proteus/ProteusLayoutInflater.java | 242 +-- .../android/proteus/ProteusResources.java | 88 +- .../flipkart/android/proteus/ProteusView.java | 136 +- .../android/proteus/SimpleIdGenerator.java | 158 +- .../android/proteus/SimpleLayoutInflater.java | 276 +-- .../android/proteus/StyleManager.java | 12 +- .../com/flipkart/android/proteus/Styles.java | 12 +- .../android/proteus/ViewTypeParser.java | 538 +++--- .../exceptions/ProteusInflateException.java | 6 +- .../managers/AdapterBasedViewManager.java | 22 +- .../proteus/managers/ViewGroupManager.java | 44 +- .../android/proteus/managers/ViewManager.java | 188 +- .../android/proteus/parser/IncludeParser.java | 58 +- .../android/proteus/parser/ParseHelper.java | 638 +++---- .../android/proteus/parser/ViewParser.java | 1094 ++++++------ .../proteus/parser/custom/ButtonParser.java | 44 +- .../proteus/parser/custom/CheckBoxParser.java | 62 +- .../proteus/parser/custom/EditTextParser.java | 46 +- .../parser/custom/FrameLayoutParser.java | 62 +- .../custom/HorizontalProgressBarParser.java | 44 +- .../custom/HorizontalScrollViewParser.java | 86 +- .../parser/custom/ImageButtonParser.java | 46 +- .../parser/custom/ImageViewParser.java | 88 +- .../parser/custom/LinearLayoutParser.java | 164 +- .../parser/custom/ProgressBarParser.java | 212 +-- .../parser/custom/RatingBarParser.java | 112 +- .../parser/custom/RelativeLayoutParser.java | 50 +- .../parser/custom/ScrollViewParser.java | 74 +- .../proteus/parser/custom/TextViewParser.java | 412 ++--- .../parser/custom/ViewGroupParser.java | 334 ++-- .../proteus/parser/custom/WebViewParser.java | 62 +- .../proteus/processor/AttributeProcessor.java | 204 +-- .../processor/BooleanAttributeProcessor.java | 54 +- .../processor/ColorResourceProcessor.java | 170 +- .../DimensionAttributeProcessor.java | 122 +- .../processor/DrawableResourceProcessor.java | 148 +- .../proteus/processor/EventProcessor.java | 54 +- .../processor/GravityAttributeProcessor.java | 126 +- .../processor/NumberAttributeProcessor.java | 38 +- .../processor/StringAttributeProcessor.java | 72 +- .../TweenAnimationResourceProcessor.java | 42 +- .../proteus/toolbox/AnimationUtils.java | 972 +++++------ .../android/proteus/toolbox/Attributes.java | 364 ++-- .../android/proteus/toolbox/BiMap.java | 26 +- .../android/proteus/toolbox/HashBiMap.java | 130 +- .../proteus/toolbox/LazilyParsedNumber.java | 104 +- .../proteus/toolbox/ManagerWrapper.java | 80 +- .../android/proteus/toolbox/Result.java | 158 +- .../proteus/toolbox/SimpleArrayIterator.java | 68 +- .../android/proteus/toolbox/Utils.java | 134 +- .../flipkart/android/proteus/value/Array.java | 376 ++-- .../proteus/value/AttributeResource.java | 138 +- .../android/proteus/value/Binding.java | 842 ++++----- .../flipkart/android/proteus/value/Color.java | 470 ++--- .../android/proteus/value/Dimension.java | 260 +-- .../android/proteus/value/DrawableValue.java | 1546 ++++++++--------- .../android/proteus/value/Layout.java | 154 +- .../android/proteus/value/NestedBinding.java | 140 +- .../flipkart/android/proteus/value/Null.java | 68 +- .../android/proteus/value/ObjectValue.java | 620 +++---- .../android/proteus/value/Primitive.java | 512 +++--- .../android/proteus/value/Resource.java | 384 ++-- .../android/proteus/value/StyleResource.java | 160 +- .../flipkart/android/proteus/value/Value.java | 616 +++---- .../proteus/view/ProteusAndroidView.java | 54 +- .../view/ProteusAspectRatioFrameLayout.java | 54 +- .../android/proteus/view/ProteusButton.java | 54 +- .../android/proteus/view/ProteusCheckBox.java | 54 +- .../android/proteus/view/ProteusEditText.java | 54 +- .../proteus/view/ProteusFixedRatingBar.java | 58 +- .../view/ProteusHorizontalProgressBar.java | 42 +- .../view/ProteusHorizontalScrollView.java | 54 +- .../proteus/view/ProteusImageButton.java | 54 +- .../proteus/view/ProteusImageView.java | 54 +- .../proteus/view/ProteusLinearLayout.java | 54 +- .../proteus/view/ProteusProgressBar.java | 54 +- .../proteus/view/ProteusRelativeLayout.java | 54 +- .../proteus/view/ProteusScrollView.java | 54 +- .../android/proteus/view/ProteusTextView.java | 54 +- .../android/proteus/view/ProteusWebView.java | 54 +- .../view/custom/AspectRatioFrameLayout.java | 110 +- .../proteus/view/custom/FixedRatingBar.java | 134 +- .../view/custom/HorizontalProgressBar.java | 6 +- .../src/test/java/android/graphics/Color.java | 112 +- .../src/test/java/android/util/LruCache.java | 532 +++--- .../test/java/android/util/TypedValue.java | 6 +- .../proteus/parser/ParseHelperTest.java | 42 +- .../GravityAttributeProcessorTest.java | 238 +-- .../android/proteus/value/BindingTest.java | 606 +++---- .../android/proteus/value/DimensionTest.java | 302 ++-- 104 files changed, 9983 insertions(+), 9985 deletions(-) diff --git a/proteus-core/AndroidManifest.xml b/proteus-core/AndroidManifest.xml index aa8f498c..5f9e5a15 100644 --- a/proteus-core/AndroidManifest.xml +++ b/proteus-core/AndroidManifest.xml @@ -1,5 +1,4 @@ - - - \ No newline at end of file + \ No newline at end of file diff --git a/proteus-core/res/layout/layout_params_hack.xml b/proteus-core/res/layout/layout_params_hack.xml index 30bed8de..0f797169 100644 --- a/proteus-core/res/layout/layout_params_hack.xml +++ b/proteus-core/res/layout/layout_params_hack.xml @@ -17,5 +17,5 @@ --> \ No newline at end of file + android:layout_width="wrap_content" + android:layout_height="wrap_content" /> \ No newline at end of file diff --git a/proteus-core/res/values/values.xml b/proteus-core/res/values/values.xml index ae2d7032..82a35768 100644 --- a/proteus-core/res/values/values.xml +++ b/proteus-core/res/values/values.xml @@ -1,5 +1,4 @@ - - - + Library \ No newline at end of file diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/BoundAttribute.java b/proteus-core/src/main/java/com/flipkart/android/proteus/BoundAttribute.java index a3903dc9..beabe7a9 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/BoundAttribute.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/BoundAttribute.java @@ -33,19 +33,19 @@ */ public class BoundAttribute { - /** - * The {@code int} attribute id of the pair. - */ - public final int attributeId; + /** + * The {@code int} attribute id of the pair. + */ + public final int attributeId; - /** - * The {@link Binding} for the layout attributes value. - */ - @NonNull - public final Binding binding; + /** + * The {@link Binding} for the layout attributes value. + */ + @NonNull + public final Binding binding; - public BoundAttribute(int attributeId, @NonNull Binding binding) { - this.attributeId = attributeId; - this.binding = binding; - } + public BoundAttribute(int attributeId, @NonNull Binding binding) { + this.attributeId = attributeId; + this.binding = binding; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/DataContext.java b/proteus-core/src/main/java/com/flipkart/android/proteus/DataContext.java index d3568bf9..a917a6e5 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/DataContext.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/DataContext.java @@ -38,175 +38,175 @@ */ public class DataContext { - /** - * This property is used to identify whether - * this data context is simply cloned from it's - * parent data context. Which implies that the - * {@link #scope} and {@link #data} were copied - * from it's parents data context. - */ - private final boolean hasOwnProperties; - - /** - * This is the local isolated scope created for this - * {@link ProteusView} hosting this instance of the - * data context. This is populated from the {@code data} - * attribute specified in the layout. - */ - @Nullable - private final Map scope; - - /** - * This index is used to resolve the {@code $index} meta - * values when dealing with arrays and data bound - * {@code children} attribute. - */ - private final int index; - - /** - * The data which will be used to bind all data bound - * attribute values of the layout. - */ - private ObjectValue data; - - /** - * This is the default constructor to create a new {@code DataContext}. - * The {@link #hasOwnProperties} is initialized to {@code true} is and - * only if the {@param scope} argument is non null. An empty non null, - * null, a {@param scope} which does not refer to any data paths from - * the parent scope implies that the hosting {@link ProteusView} is - * completely isolated from the parent and cannot access any data from - * above it in the hierarchy. - * - * @param scope the local isolate scope for this data context. - * @param index the data index for this data context. - */ - private DataContext(@Nullable Map scope, int index) { - this.scope = scope; - this.index = index; - this.hasOwnProperties = scope != null; + /** + * This property is used to identify whether + * this data context is simply cloned from it's + * parent data context. Which implies that the + * {@link #scope} and {@link #data} were copied + * from it's parents data context. + */ + private final boolean hasOwnProperties; + + /** + * This is the local isolated scope created for this + * {@link ProteusView} hosting this instance of the + * data context. This is populated from the {@code data} + * attribute specified in the layout. + */ + @Nullable + private final Map scope; + + /** + * This index is used to resolve the {@code $index} meta + * values when dealing with arrays and data bound + * {@code children} attribute. + */ + private final int index; + + /** + * The data which will be used to bind all data bound + * attribute values of the layout. + */ + private ObjectValue data; + + /** + * This is the default constructor to create a new {@code DataContext}. + * The {@link #hasOwnProperties} is initialized to {@code true} is and + * only if the {@param scope} argument is non null. An empty non null, + * null, a {@param scope} which does not refer to any data paths from + * the parent scope implies that the hosting {@link ProteusView} is + * completely isolated from the parent and cannot access any data from + * above it in the hierarchy. + * + * @param scope the local isolate scope for this data context. + * @param index the data index for this data context. + */ + private DataContext(@Nullable Map scope, int index) { + this.scope = scope; + this.index = index; + this.hasOwnProperties = scope != null; + } + + /** + * This is a copy constructor for creating a clone of + * another data context. The {@link #hasOwnProperties} + * is always {@code false} for a cloned data context. + * + * @param dataContext the parent data context to clone from. + */ + public DataContext(DataContext dataContext) { + this.data = dataContext.getData(); + this.scope = dataContext.getScope(); + this.index = dataContext.getIndex(); + this.hasOwnProperties = false; + } + + /** + * Utility method to create a new {@link DataContext} without any {@link #scope}. + * + * @param context The proteus context to resolve {@link FunctionBinding} to evaluate the scope. + * @param data The data to be used by the data context. + * @param dataIndex The data index to used by the data context. + * @return A new data context with scope evaluated. + */ + public static DataContext create(@NonNull ProteusContext context, @Nullable ObjectValue data, int dataIndex) { + DataContext dataContext = new DataContext(null, dataIndex); + dataContext.update(context, data); + return dataContext; + } + + /** + * Utility method to create a new {@link DataContext} with a {@link #scope}. + * + * @param context The proteus android context to resolve {@link FunctionBinding} to evaluate the scope. + * @param data The data to be used by the data context. + * @param dataIndex The data index to used by the data context. + * @param scope The scope map used to create the {@link #data} of this data context. + * @return A new data context with scope evaluated. + */ + public static DataContext create(@NonNull ProteusContext context, @Nullable ObjectValue data, + int dataIndex, @Nullable Map scope) { + DataContext dataContext = new DataContext(scope, dataIndex); + dataContext.update(context, data); + return dataContext; + } + + /** + * Update this data context with new data. + * + * @param context The proteus context used to evaluate {@link FunctionBinding} to evaluate the scope. + * @param in The new data. + */ + public void update(@NonNull ProteusContext context, @Nullable ObjectValue in) { + if (in == null) { + in = new ObjectValue(); } - /** - * This is a copy constructor for creating a clone of - * another data context. The {@link #hasOwnProperties} - * is always {@code false} for a cloned data context. - * - * @param dataContext the parent data context to clone from. - */ - public DataContext(DataContext dataContext) { - this.data = dataContext.getData(); - this.scope = dataContext.getScope(); - this.index = dataContext.getIndex(); - this.hasOwnProperties = false; + if (scope == null) { + data = in; + return; } - /** - * Utility method to create a new {@link DataContext} without any {@link #scope}. - * - * @param context The proteus context to resolve {@link FunctionBinding} to evaluate the scope. - * @param data The data to be used by the data context. - * @param dataIndex The data index to used by the data context. - * @return A new data context with scope evaluated. - */ - public static DataContext create(@NonNull ProteusContext context, @Nullable ObjectValue data, int dataIndex) { - DataContext dataContext = new DataContext(null, dataIndex); - dataContext.update(context, data); - return dataContext; - } - - /** - * Utility method to create a new {@link DataContext} with a {@link #scope}. - * - * @param context The proteus android context to resolve {@link FunctionBinding} to evaluate the scope. - * @param data The data to be used by the data context. - * @param dataIndex The data index to used by the data context. - * @param scope The scope map used to create the {@link #data} of this data context. - * @return A new data context with scope evaluated. - */ - public static DataContext create(@NonNull ProteusContext context, @Nullable ObjectValue data, - int dataIndex, @Nullable Map scope) { - DataContext dataContext = new DataContext(scope, dataIndex); - dataContext.update(context, data); - return dataContext; - } + ObjectValue out = new ObjectValue(); - /** - * Update this data context with new data. - * - * @param context The proteus context used to evaluate {@link FunctionBinding} to evaluate the scope. - * @param in The new data. - */ - public void update(@NonNull ProteusContext context, @Nullable ObjectValue in) { - if (in == null) { - in = new ObjectValue(); + for (Map.Entry entry : scope.entrySet()) { + String key = entry.getKey(); + Value value = entry.getValue(); + Value resolved; + if (value.isBinding()) { + resolved = value.getAsBinding().evaluate(context, out, index); + if (resolved == Null.INSTANCE) { + resolved = value.getAsBinding().evaluate(context, in, index); } - - if (scope == null) { - data = in; - return; - } - - ObjectValue out = new ObjectValue(); - - for (Map.Entry entry : scope.entrySet()) { - String key = entry.getKey(); - Value value = entry.getValue(); - Value resolved; - if (value.isBinding()) { - resolved = value.getAsBinding().evaluate(context, out, index); - if (resolved == Null.INSTANCE) { - resolved = value.getAsBinding().evaluate(context, in, index); - } - } else { - resolved = value; - } - out.add(key, resolved); - } - - data = out; + } else { + resolved = value; + } + out.add(key, resolved); } - /** - * A utility method to create a child data context, with its own scope and index from the data - * of this data context. - * - * @param context The proteus context used to evaluate {@link FunctionBinding} to evaluate the scope. - * @param scope The scope for the new data context - * @param dataIndex The data index to used by the new data context. - * @return A new data context with scope evaluated. - */ - public DataContext createChild(@NonNull ProteusContext context, @NonNull Map scope, int dataIndex) { - return create(context, data, dataIndex, scope); - } - - /** - * Returns a clone of this data context with {@link #hasOwnProperties} set to {@code false}. - * - * @return a new cloned data context. - */ - public DataContext copy() { - return new DataContext(this); - } - - public ObjectValue getData() { - return data; - } - - public void setData(ObjectValue data) { - this.data = data; - } - - @Nullable - public Map getScope() { - return scope; - } - - public boolean hasOwnProperties() { - return hasOwnProperties; - } - - public int getIndex() { - return index; - } + data = out; + } + + /** + * A utility method to create a child data context, with its own scope and index from the data + * of this data context. + * + * @param context The proteus context used to evaluate {@link FunctionBinding} to evaluate the scope. + * @param scope The scope for the new data context + * @param dataIndex The data index to used by the new data context. + * @return A new data context with scope evaluated. + */ + public DataContext createChild(@NonNull ProteusContext context, @NonNull Map scope, int dataIndex) { + return create(context, data, dataIndex, scope); + } + + /** + * Returns a clone of this data context with {@link #hasOwnProperties} set to {@code false}. + * + * @return a new cloned data context. + */ + public DataContext copy() { + return new DataContext(this); + } + + public ObjectValue getData() { + return data; + } + + public void setData(ObjectValue data) { + this.data = data; + } + + @Nullable + public Map getScope() { + return scope; + } + + public boolean hasOwnProperties() { + return hasOwnProperties; + } + + public int getIndex() { + return index; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/Function.java b/proteus-core/src/main/java/com/flipkart/android/proteus/Function.java index bd8d6549..9a18e74b 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/Function.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/Function.java @@ -36,644 +36,644 @@ */ public abstract class Function { - // SPECIAL + // SPECIAL - public static final Function NOOP = new Function() { - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - return ProteusConstants.EMPTY_STRING; - } - - @Override - public String getName() { - return "noop"; - } - }; - - @SuppressLint("SimpleDateFormat") - public static final Function DATE = new Function() { - - private SimpleDateFormat from = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - private SimpleDateFormat to = new SimpleDateFormat("E, d MMM"); - - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - Date in = getFromFormat(arguments).parse(arguments[0].getAsString()); - String out = getToFormat(arguments).format(in); - return new Primitive(out); - } - - private SimpleDateFormat getFromFormat(Value[] arguments) { - if (arguments.length > 2) { - return new SimpleDateFormat(arguments[2].getAsString()); - } else { - return from; - } - } - - private SimpleDateFormat getToFormat(Value[] arguments) { - if (arguments.length > 1) { - return new SimpleDateFormat(arguments[1].getAsString()); - } else { - return to; - } - } - - @Override - public String getName() { - return "date"; - } - }; - - public static final Function FORMAT = new Function() { - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - String template = arguments[0].getAsString(); - String[] values = new String[arguments.length - 1]; - for (int i = 1; i < arguments.length; i++) { - values[i - 1] = arguments[i].getAsString(); - } - return new Primitive(String.format(template, (Object[]) values)); - } - - @Override - public String getName() { - return "format"; - } - }; - - public static final Function JOIN = new Function() { - - private static final String DEFAULT_DELIMITER = ", "; - - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - return new Primitive(Utils.join(arguments[0].getAsArray(), getDelimiter(arguments))); - } - - private String getDelimiter(Value[] arguments) { - if (arguments.length > 1) { - return arguments[1].getAsString(); - } - return DEFAULT_DELIMITER; - } - - @Override - public String getName() { - return "join"; - } - }; - - public static final Function NUMBER = new Function() { - - private final DecimalFormat DEFAULT_FORMATTER = new DecimalFormat("#,###"); - - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - double number = Double.parseDouble(arguments[0].getAsString()); - DecimalFormat formatter = getFormatter(arguments); - formatter.setRoundingMode(RoundingMode.FLOOR); - formatter.setMinimumFractionDigits(0); - formatter.setMaximumFractionDigits(2); - return new Primitive(formatter.format(number)); - } - - private DecimalFormat getFormatter(Value[] arguments) { - if (arguments.length > 1) { - return new DecimalFormat(arguments[1].getAsString()); - } - return DEFAULT_FORMATTER; - } - - @Override - public String getName() { - return "number"; - } - }; - - // Mathematical - - public static final Function ADD = new Function() { - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - double sum = 0; - - for (Value argument : arguments) { - sum = sum + argument.getAsDouble(); - } - - return new Primitive(sum); - } + public static final Function NOOP = new Function() { + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + return ProteusConstants.EMPTY_STRING; + } - @Override - public String getName() { - return "add"; - } - }; + @Override + public String getName() { + return "noop"; + } + }; - public static final Function SUBTRACT = new Function() { - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - double sum = arguments[0].getAsDouble(); + @SuppressLint("SimpleDateFormat") + public static final Function DATE = new Function() { - for (int i = 1; i < arguments.length; i++) { - sum = sum - arguments[i].getAsDouble(); - } + private SimpleDateFormat from = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + private SimpleDateFormat to = new SimpleDateFormat("E, d MMM"); - return new Primitive(sum); - } - - @Override - public String getName() { - return "sub"; - } - }; + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + Date in = getFromFormat(arguments).parse(arguments[0].getAsString()); + String out = getToFormat(arguments).format(in); + return new Primitive(out); + } + + private SimpleDateFormat getFromFormat(Value[] arguments) { + if (arguments.length > 2) { + return new SimpleDateFormat(arguments[2].getAsString()); + } else { + return from; + } + } + + private SimpleDateFormat getToFormat(Value[] arguments) { + if (arguments.length > 1) { + return new SimpleDateFormat(arguments[1].getAsString()); + } else { + return to; + } + } + + @Override + public String getName() { + return "date"; + } + }; + + public static final Function FORMAT = new Function() { + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + String template = arguments[0].getAsString(); + String[] values = new String[arguments.length - 1]; + for (int i = 1; i < arguments.length; i++) { + values[i - 1] = arguments[i].getAsString(); + } + return new Primitive(String.format(template, (Object[]) values)); + } + + @Override + public String getName() { + return "format"; + } + }; + + public static final Function JOIN = new Function() { + + private static final String DEFAULT_DELIMITER = ", "; - public static final Function MULTIPLY = new Function() { - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - double product = 1; + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + return new Primitive(Utils.join(arguments[0].getAsArray(), getDelimiter(arguments))); + } - for (Value argument : arguments) { - product = product * argument.getAsDouble(); - } + private String getDelimiter(Value[] arguments) { + if (arguments.length > 1) { + return arguments[1].getAsString(); + } + return DEFAULT_DELIMITER; + } - return new Primitive(product); - } + @Override + public String getName() { + return "join"; + } + }; - @Override - public String getName() { - return "mul"; - } - }; + public static final Function NUMBER = new Function() { - public static final Function DIVIDE = new Function() { - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - double quotient = arguments[0].getAsDouble(); + private final DecimalFormat DEFAULT_FORMATTER = new DecimalFormat("#,###"); - for (int i = 1; i < arguments.length; i++) { - quotient = quotient / arguments[i].getAsDouble(); - } + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + double number = Double.parseDouble(arguments[0].getAsString()); + DecimalFormat formatter = getFormatter(arguments); + formatter.setRoundingMode(RoundingMode.FLOOR); + formatter.setMinimumFractionDigits(0); + formatter.setMaximumFractionDigits(2); + return new Primitive(formatter.format(number)); + } + + private DecimalFormat getFormatter(Value[] arguments) { + if (arguments.length > 1) { + return new DecimalFormat(arguments[1].getAsString()); + } + return DEFAULT_FORMATTER; + } + + @Override + public String getName() { + return "number"; + } + }; + + // Mathematical + + public static final Function ADD = new Function() { + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + double sum = 0; - return new Primitive(quotient); - } + for (Value argument : arguments) { + sum = sum + argument.getAsDouble(); + } - @Override - public String getName() { - return "div"; - } - }; + return new Primitive(sum); + } - public static final Function MODULO = new Function() { - @NonNull - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - double remainder = arguments[0].getAsDouble(); + @Override + public String getName() { + return "add"; + } + }; - for (int i = 1; i < arguments.length; i++) { - remainder = remainder % arguments[i].getAsDouble(); - } + public static final Function SUBTRACT = new Function() { + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + double sum = arguments[0].getAsDouble(); - return new Primitive(remainder); - } + for (int i = 1; i < arguments.length; i++) { + sum = sum - arguments[i].getAsDouble(); + } - @Override - public String getName() { - return "mod"; - } - }; - - // Logical - - public static final Function AND = new Function() { - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - if (arguments.length < 1) { - return ProteusConstants.FALSE; - } - boolean bool = true; - for (Value argument : arguments) { - bool = ParseHelper.parseBoolean(argument); - if (!bool) { - break; - } - } - - return bool ? ProteusConstants.TRUE : ProteusConstants.FALSE; - } + return new Primitive(sum); + } - @Override - public String getName() { - return "and"; - } - }; - - public static final Function OR = new Function() { - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - if (arguments.length < 1) { - return ProteusConstants.FALSE; - } - boolean bool = false; - for (Value argument : arguments) { - bool = ParseHelper.parseBoolean(argument); - if (bool) { - break; - } - } - - return bool ? ProteusConstants.TRUE : ProteusConstants.FALSE; - } + @Override + public String getName() { + return "sub"; + } + }; - @Override - public String getName() { - return "or"; - } - }; - - // Unary - - public static final Function NOT = new Function() { - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - if (arguments.length < 1) { - return ProteusConstants.TRUE; - } - return ParseHelper.parseBoolean(arguments[0]) ? ProteusConstants.FALSE : ProteusConstants.TRUE; - } - - @Override - public String getName() { - return "not"; - } - }; - - // Comparison - - public static final Function EQUALS = new Function() { - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - if (arguments.length < 2) { - return ProteusConstants.FALSE; - } - - Value x = arguments[0]; - Value y = arguments[1]; - boolean bool = false; - if (x.isPrimitive() && y.isPrimitive()) { - bool = x.getAsPrimitive().equals(y.getAsPrimitive()); - } - - return bool ? ProteusConstants.TRUE : ProteusConstants.FALSE; - } + public static final Function MULTIPLY = new Function() { + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + double product = 1; - @Override - public String getName() { - return "eq"; - } - }; - - public static final Function LESS_THAN = new Function() { - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - if (arguments.length < 2) { - return ProteusConstants.FALSE; - } - - Value x = arguments[0]; - Value y = arguments[1]; - boolean bool = false; - if (x.isPrimitive() && y.isPrimitive()) { - bool = x.getAsPrimitive().getAsDouble() < y.getAsPrimitive().getAsDouble(); - } - - return bool ? ProteusConstants.TRUE : ProteusConstants.FALSE; - } + for (Value argument : arguments) { + product = product * argument.getAsDouble(); + } - @Override - public String getName() { - return "lt"; - } - }; - - public static final Function GREATER_THAN = new Function() { - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - if (arguments.length < 2) { - return ProteusConstants.FALSE; - } - - Value x = arguments[0]; - Value y = arguments[1]; - boolean bool = false; - if (x.isPrimitive() && y.isPrimitive()) { - bool = x.getAsPrimitive().getAsDouble() > y.getAsPrimitive().getAsDouble(); - } - - return bool ? ProteusConstants.TRUE : ProteusConstants.FALSE; - } + return new Primitive(product); + } - @Override - public String getName() { - return "gt"; - } - }; - - public static final Function LESS_THAN_OR_EQUALS = new Function() { - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - if (arguments.length < 2) { - return ProteusConstants.FALSE; - } - - Value x = arguments[0]; - Value y = arguments[1]; - boolean bool = false; - if (x.isPrimitive() && y.isPrimitive()) { - bool = x.getAsPrimitive().getAsDouble() <= y.getAsPrimitive().getAsDouble(); - } - - return bool ? ProteusConstants.TRUE : ProteusConstants.FALSE; - } + @Override + public String getName() { + return "mul"; + } + }; - @Override - public String getName() { - return "lte"; - } - }; - - public static final Function GREATER_THAN_OR_EQUALS = new Function() { - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - if (arguments.length < 2) { - return ProteusConstants.FALSE; - } - - Value x = arguments[0]; - Value y = arguments[1]; - boolean bool = false; - if (x.isPrimitive() && y.isPrimitive()) { - bool = x.getAsPrimitive().getAsDouble() >= y.getAsPrimitive().getAsDouble(); - } - - return bool ? ProteusConstants.TRUE : ProteusConstants.FALSE; - } + public static final Function DIVIDE = new Function() { + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + double quotient = arguments[0].getAsDouble(); - @Override - public String getName() { - return "gte"; - } - }; + for (int i = 1; i < arguments.length; i++) { + quotient = quotient / arguments[i].getAsDouble(); + } - // Conditional + return new Primitive(quotient); + } - public static final Function TERNARY = new Function() { - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - Value i = arguments[0]; - Value t = arguments[1]; - Value e = arguments[2]; + @Override + public String getName() { + return "div"; + } + }; - return ParseHelper.parseBoolean(i) ? t : e; - } + public static final Function MODULO = new Function() { + @NonNull + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + double remainder = arguments[0].getAsDouble(); - @Override - public String getName() { - return "ternary"; - } - }; - - // String - - //String.charAt() - public static final Function CHAR_AT = new Function() { - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - String string = arguments[0].getAsString(); - int index = arguments[1].getAsInt(); - char charAtIndex = string.charAt(index); - return new Primitive(charAtIndex); - } + for (int i = 1; i < arguments.length; i++) { + remainder = remainder % arguments[i].getAsDouble(); + } - @Override - public String getName() { - return "charAt"; - } - }; - - //String.contains() - public static final Function CONTAINS = new Function() { - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - String string = arguments[0].getAsString(); - String substring = arguments[1].getAsString(); - boolean bool = string.contains(substring); - return new Primitive(bool); - } + return new Primitive(remainder); + } - @Override - public String getName() { - return "contains"; - } - }; - - //String.endsWith() - //String.indexOf() - - //String.isEmpty() - public static final Function IS_EMPTY = new Function() { - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - String string = arguments[0].getAsString(); - return new Primitive(ProteusConstants.EMPTY.equals(string)); - } + @Override + public String getName() { + return "mod"; + } + }; - @Override - public String getName() { - return "isEmpty"; - } - }; - - //String.lastIndexOf() - - //String.length() - public static final Function LENGTH = new Function() { - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - Value value = arguments[0]; - int length = 0; - if (value.isPrimitive()) { - length = value.getAsString().length(); - } else if (value.isArray()) { - length = value.getAsArray().size(); - } - return new Primitive(length); - } + // Logical - @Override - public String getName() { - return "length"; - } - }; - - //String.matches() - //String.replace() - //String.replaceAll() - //String.replaceFirst() - //String.split() - //String.startsWith() - //String.substring() - //String.toLowerCase() - //String.toUpperCase() - - //String.trim() - public static final Function TRIM = new Function() { - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - String string = arguments[0].getAsString().trim(); - return new Primitive(string); - } + public static final Function AND = new Function() { + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + if (arguments.length < 1) { + return ProteusConstants.FALSE; + } + boolean bool = true; + for (Value argument : arguments) { + bool = ParseHelper.parseBoolean(argument); + if (!bool) { + break; + } + } + + return bool ? ProteusConstants.TRUE : ProteusConstants.FALSE; + } + + @Override + public String getName() { + return "and"; + } + }; + + public static final Function OR = new Function() { + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + if (arguments.length < 1) { + return ProteusConstants.FALSE; + } + boolean bool = false; + for (Value argument : arguments) { + bool = ParseHelper.parseBoolean(argument); + if (bool) { + break; + } + } + + return bool ? ProteusConstants.TRUE : ProteusConstants.FALSE; + } + + @Override + public String getName() { + return "or"; + } + }; + + // Unary + + public static final Function NOT = new Function() { + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + if (arguments.length < 1) { + return ProteusConstants.TRUE; + } + return ParseHelper.parseBoolean(arguments[0]) ? ProteusConstants.FALSE : ProteusConstants.TRUE; + } + + @Override + public String getName() { + return "not"; + } + }; + + // Comparison + + public static final Function EQUALS = new Function() { + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + if (arguments.length < 2) { + return ProteusConstants.FALSE; + } + + Value x = arguments[0]; + Value y = arguments[1]; + boolean bool = false; + if (x.isPrimitive() && y.isPrimitive()) { + bool = x.getAsPrimitive().equals(y.getAsPrimitive()); + } + + return bool ? ProteusConstants.TRUE : ProteusConstants.FALSE; + } + + @Override + public String getName() { + return "eq"; + } + }; + + public static final Function LESS_THAN = new Function() { + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + if (arguments.length < 2) { + return ProteusConstants.FALSE; + } + + Value x = arguments[0]; + Value y = arguments[1]; + boolean bool = false; + if (x.isPrimitive() && y.isPrimitive()) { + bool = x.getAsPrimitive().getAsDouble() < y.getAsPrimitive().getAsDouble(); + } + + return bool ? ProteusConstants.TRUE : ProteusConstants.FALSE; + } + + @Override + public String getName() { + return "lt"; + } + }; + + public static final Function GREATER_THAN = new Function() { + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + if (arguments.length < 2) { + return ProteusConstants.FALSE; + } + + Value x = arguments[0]; + Value y = arguments[1]; + boolean bool = false; + if (x.isPrimitive() && y.isPrimitive()) { + bool = x.getAsPrimitive().getAsDouble() > y.getAsPrimitive().getAsDouble(); + } + + return bool ? ProteusConstants.TRUE : ProteusConstants.FALSE; + } + + @Override + public String getName() { + return "gt"; + } + }; + + public static final Function LESS_THAN_OR_EQUALS = new Function() { + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + if (arguments.length < 2) { + return ProteusConstants.FALSE; + } + + Value x = arguments[0]; + Value y = arguments[1]; + boolean bool = false; + if (x.isPrimitive() && y.isPrimitive()) { + bool = x.getAsPrimitive().getAsDouble() <= y.getAsPrimitive().getAsDouble(); + } + + return bool ? ProteusConstants.TRUE : ProteusConstants.FALSE; + } + + @Override + public String getName() { + return "lte"; + } + }; + + public static final Function GREATER_THAN_OR_EQUALS = new Function() { + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + if (arguments.length < 2) { + return ProteusConstants.FALSE; + } + + Value x = arguments[0]; + Value y = arguments[1]; + boolean bool = false; + if (x.isPrimitive() && y.isPrimitive()) { + bool = x.getAsPrimitive().getAsDouble() >= y.getAsPrimitive().getAsDouble(); + } + + return bool ? ProteusConstants.TRUE : ProteusConstants.FALSE; + } + + @Override + public String getName() { + return "gte"; + } + }; + + // Conditional + + public static final Function TERNARY = new Function() { + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + Value i = arguments[0]; + Value t = arguments[1]; + Value e = arguments[2]; - @Override - public String getName() { - return "trim"; - } - }; - - //String.subSequence() - - // Math - - //Math.abs - //Math.ceil - //Math.floor - //Math.pow - //Math.round - //Math.random - - //Math.max - public static final Function MAX = new Function() { - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - double max = arguments[0].getAsDouble(); - double current; - for (int i = 1; i < arguments.length; i++) { - current = arguments[i].getAsDouble(); - if (current > max) { - max = current; - } - } - return new Primitive(max); - } + return ParseHelper.parseBoolean(i) ? t : e; + } - @Override - public String getName() { - return "max"; - } - }; - - //Math.min - public static final Function MIN = new Function() { - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - double min = arguments[0].getAsDouble(); - double current; - for (int i = 1; i < arguments.length; i++) { - current = arguments[i].getAsDouble(); - if (current < min) { - min = current; - } - } - return new Primitive(min); - } + @Override + public String getName() { + return "ternary"; + } + }; - @Override - public String getName() { - return "min"; - } - }; - - // Array - - public static final Function SLICE = new Function() { - @NonNull - @Override - public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { - Array in = arguments[0].getAsArray(); - int start = getStart(in, arguments); - int end = getEnd(in, arguments); - Array out = new Array(); - for (int i = start; i < end; i++) { - out.add(in.get(i)); - } - return out; - } + // String - private int getStart(Array in, Value[] arguments) { - if (arguments.length > 1) { - int index = arguments[1].getAsInt(); - if (index < 0) { - index = in.size() - index; - if (index < 0) { - return 0; - } - } else if (index > in.size()) { - index = in.size(); - } - return index; - } + //String.charAt() + public static final Function CHAR_AT = new Function() { + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + String string = arguments[0].getAsString(); + int index = arguments[1].getAsInt(); + char charAtIndex = string.charAt(index); + return new Primitive(charAtIndex); + } + + @Override + public String getName() { + return "charAt"; + } + }; + + //String.contains() + public static final Function CONTAINS = new Function() { + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + String string = arguments[0].getAsString(); + String substring = arguments[1].getAsString(); + boolean bool = string.contains(substring); + return new Primitive(bool); + } + + @Override + public String getName() { + return "contains"; + } + }; + + //String.endsWith() + //String.indexOf() + + //String.isEmpty() + public static final Function IS_EMPTY = new Function() { + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + String string = arguments[0].getAsString(); + return new Primitive(ProteusConstants.EMPTY.equals(string)); + } + + @Override + public String getName() { + return "isEmpty"; + } + }; + + //String.lastIndexOf() + + //String.length() + public static final Function LENGTH = new Function() { + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + Value value = arguments[0]; + int length = 0; + if (value.isPrimitive()) { + length = value.getAsString().length(); + } else if (value.isArray()) { + length = value.getAsArray().size(); + } + return new Primitive(length); + } + + @Override + public String getName() { + return "length"; + } + }; + + //String.matches() + //String.replace() + //String.replaceAll() + //String.replaceFirst() + //String.split() + //String.startsWith() + //String.substring() + //String.toLowerCase() + //String.toUpperCase() + + //String.trim() + public static final Function TRIM = new Function() { + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + String string = arguments[0].getAsString().trim(); + return new Primitive(string); + } + + @Override + public String getName() { + return "trim"; + } + }; + + //String.subSequence() + + // Math + + //Math.abs + //Math.ceil + //Math.floor + //Math.pow + //Math.round + //Math.random + + //Math.max + public static final Function MAX = new Function() { + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + double max = arguments[0].getAsDouble(); + double current; + for (int i = 1; i < arguments.length; i++) { + current = arguments[i].getAsDouble(); + if (current > max) { + max = current; + } + } + return new Primitive(max); + } + + @Override + public String getName() { + return "max"; + } + }; + + //Math.min + public static final Function MIN = new Function() { + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + double min = arguments[0].getAsDouble(); + double current; + for (int i = 1; i < arguments.length; i++) { + current = arguments[i].getAsDouble(); + if (current < min) { + min = current; + } + } + return new Primitive(min); + } + + @Override + public String getName() { + return "min"; + } + }; + + // Array + + public static final Function SLICE = new Function() { + @NonNull + @Override + public Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception { + Array in = arguments[0].getAsArray(); + int start = getStart(in, arguments); + int end = getEnd(in, arguments); + Array out = new Array(); + for (int i = start; i < end; i++) { + out.add(in.get(i)); + } + return out; + } + + private int getStart(Array in, Value[] arguments) { + if (arguments.length > 1) { + int index = arguments[1].getAsInt(); + if (index < 0) { + index = in.size() - index; + if (index < 0) { return 0; + } + } else if (index > in.size()) { + index = in.size(); + } + return index; + } + return 0; + } + + private int getEnd(Array in, Value[] arguments) { + if (arguments.length > 2) { + int index = arguments[2].getAsInt(); + if (index < 0) { + index = in.size() - index; + if (index < 0) { + return 0; + } + } else if (index > in.size()) { + index = in.size(); } + return index; + } + return in.size(); + } - private int getEnd(Array in, Value[] arguments) { - if (arguments.length > 2) { - int index = arguments[2].getAsInt(); - if (index < 0) { - index = in.size() - index; - if (index < 0) { - return 0; - } - } else if (index > in.size()) { - index = in.size(); - } - return index; - } - return in.size(); - } - - @Override - public String getName() { - return "slice"; - } - }; + @Override + public String getName() { + return "slice"; + } + }; - @NonNull - public abstract Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception; + @NonNull + public abstract Value call(Context context, Value data, int dataIndex, Value... arguments) throws Exception; - public abstract String getName(); + public abstract String getName(); } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/FunctionManager.java b/proteus-core/src/main/java/com/flipkart/android/proteus/FunctionManager.java index 5e9a226a..62e6fca1 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/FunctionManager.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/FunctionManager.java @@ -27,19 +27,19 @@ */ public class FunctionManager { - @NonNull - private final Map functions; + @NonNull + private final Map functions; - public FunctionManager(@NonNull Map functions) { - this.functions = functions; - } + public FunctionManager(@NonNull Map functions) { + this.functions = functions; + } - @NonNull - public Function get(@NonNull String name) { - Function function = functions.get(name); - if (function == null) { - function = Function.NOOP; - } - return function; + @NonNull + public Function get(@NonNull String name) { + Function function = functions.get(name); + if (function == null) { + function = Function.NOOP; } + return function; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/IdGenerator.java b/proteus-core/src/main/java/com/flipkart/android/proteus/IdGenerator.java index c735c0c4..281c76be 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/IdGenerator.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/IdGenerator.java @@ -29,13 +29,13 @@ * @author aditya.sharat */ public interface IdGenerator extends Parcelable { - /** - * Generates and returns a unique id, for the given key. - * If key exists, returns old value. - * Ensure that all - * - * @param id the value for which the ID is returns. - * @return a unique ID integer for use with {@link android.view.View#setId(int)}. - */ - int getUnique(String id); + /** + * Generates and returns a unique id, for the given key. + * If key exists, returns old value. + * Ensure that all + * + * @param id the value for which the ID is returns. + * @return a unique ID integer for use with {@link android.view.View#setId(int)}. + */ + int getUnique(String id); } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/LayoutManager.java b/proteus-core/src/main/java/com/flipkart/android/proteus/LayoutManager.java index 7317c870..b7384991 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/LayoutManager.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/LayoutManager.java @@ -30,11 +30,11 @@ */ public abstract class LayoutManager { - @Nullable - protected abstract Map getLayouts(); + @Nullable + protected abstract Map getLayouts(); - @Nullable - public Layout get(@NonNull String name) { - return null != getLayouts() ? getLayouts().get(name) : null; - } + @Nullable + public Layout get(@NonNull String name) { + return null != getLayouts() ? getLayouts().get(name) : null; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/Proteus.java b/proteus-core/src/main/java/com/flipkart/android/proteus/Proteus.java index b53a2cab..8ae72b31 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/Proteus.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/Proteus.java @@ -32,66 +32,66 @@ public final class Proteus { - @NonNull - public final FunctionManager functions; - - @NonNull - private final Map types; - - @NonNull - private final Map parsers; - - Proteus(@NonNull Map types, @NonNull final Map functions) { - this.types = types; - this.functions = new FunctionManager(functions); - this.parsers = map(types); - } - - public boolean has(@NonNull @Size(min = 1) String type) { - return types.containsKey(type); - } - - @Nullable - public ViewTypeParser.AttributeSet.Attribute getAttributeId(@NonNull @Size(min = 1) String name, @NonNull @Size(min = 1) String type) { - return types.get(type).getAttributeId(name); + @NonNull + public final FunctionManager functions; + + @NonNull + private final Map types; + + @NonNull + private final Map parsers; + + Proteus(@NonNull Map types, @NonNull final Map functions) { + this.types = types; + this.functions = new FunctionManager(functions); + this.parsers = map(types); + } + + public boolean has(@NonNull @Size(min = 1) String type) { + return types.containsKey(type); + } + + @Nullable + public ViewTypeParser.AttributeSet.Attribute getAttributeId(@NonNull @Size(min = 1) String name, @NonNull @Size(min = 1) String type) { + return types.get(type).getAttributeId(name); + } + + private Map map(Map types) { + Map parsers = new HashMap<>(types.size()); + for (Map.Entry entry : types.entrySet()) { + parsers.put(entry.getKey(), entry.getValue().parser); } + return parsers; + } - private Map map(Map types) { - Map parsers = new HashMap<>(types.size()); - for (Map.Entry entry : types.entrySet()) { - parsers.put(entry.getKey(), entry.getValue().parser); - } - return parsers; - } + @NonNull + public ProteusContext createContext(@NonNull Context base) { + return createContextBuilder(base).build(); + } - @NonNull - public ProteusContext createContext(@NonNull Context base) { - return createContextBuilder(base).build(); - } + @NonNull + public ProteusContext.Builder createContextBuilder(@NonNull Context base) { + return new ProteusContext.Builder(base, parsers, functions); + } - @NonNull - public ProteusContext.Builder createContextBuilder(@NonNull Context base) { - return new ProteusContext.Builder(base, parsers, functions); - } + public static class Type { - public static class Type { + public final int id; + public final String type; + public final ViewTypeParser parser; - public final int id; - public final String type; - public final ViewTypeParser parser; + private final ViewTypeParser.AttributeSet attributes; - private final ViewTypeParser.AttributeSet attributes; - - Type(int id, @NonNull String type, @NonNull ViewTypeParser parser, @NonNull ViewTypeParser.AttributeSet attributes) { - this.id = id; - this.type = type; - this.parser = parser; - this.attributes = attributes; - } + Type(int id, @NonNull String type, @NonNull ViewTypeParser parser, @NonNull ViewTypeParser.AttributeSet attributes) { + this.id = id; + this.type = type; + this.parser = parser; + this.attributes = attributes; + } - @Nullable - public ViewTypeParser.AttributeSet.Attribute getAttributeId(String name) { - return attributes.getAttribute(name); - } + @Nullable + public ViewTypeParser.AttributeSet.Attribute getAttributeId(String name) { + return attributes.getAttribute(name); } + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusBuilder.java b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusBuilder.java index c3bd42de..4c0d7fd4 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusBuilder.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusBuilder.java @@ -51,149 +51,149 @@ public class ProteusBuilder { - /** - * The Default Module of Proteus. - */ - public static final Module DEFAULT_MODULE = new Module() { - - @Override - public void registerWith(ProteusBuilder builder) { - - // register the default parsers - builder.register(new ViewParser()); - builder.register(new IncludeParser()); - builder.register(new ViewGroupParser()); - builder.register(new RelativeLayoutParser()); - builder.register(new LinearLayoutParser()); - builder.register(new FrameLayoutParser()); - builder.register(new ScrollViewParser()); - builder.register(new HorizontalScrollViewParser()); - builder.register(new ImageViewParser()); - builder.register(new TextViewParser()); - builder.register(new EditTextParser()); - builder.register(new ButtonParser()); - builder.register(new ImageButtonParser()); - builder.register(new WebViewParser()); - builder.register(new RatingBarParser()); - builder.register(new CheckBoxParser()); - builder.register(new ProgressBarParser()); - builder.register(new HorizontalProgressBarParser()); - - // register the default functions - builder.register(Function.DATE); - builder.register(Function.FORMAT); - builder.register(Function.JOIN); - builder.register(Function.NUMBER); - - builder.register(Function.ADD); - builder.register(Function.SUBTRACT); - builder.register(Function.MULTIPLY); - builder.register(Function.DIVIDE); - builder.register(Function.MODULO); - - builder.register(Function.AND); - builder.register(Function.OR); - - builder.register(Function.NOT); - - builder.register(Function.EQUALS); - builder.register(Function.LESS_THAN); - builder.register(Function.GREATER_THAN); - builder.register(Function.LESS_THAN_OR_EQUALS); - builder.register(Function.GREATER_THAN_OR_EQUALS); - - builder.register(Function.TERNARY); - - builder.register(Function.CHAR_AT); - builder.register(Function.CONTAINS); - builder.register(Function.IS_EMPTY); - builder.register(Function.LENGTH); - builder.register(Function.TRIM); - - builder.register(Function.MAX); - builder.register(Function.MIN); - - builder.register(Function.SLICE); - } - }; - - private static final int ID = -1; - private Map> processors = new LinkedHashMap<>(); - private Map parsers = new LinkedHashMap<>(); - private HashMap functions = new HashMap<>(); - - public ProteusBuilder() { - DEFAULT_MODULE.registerWith(this); + /** + * The Default Module of Proteus. + */ + public static final Module DEFAULT_MODULE = new Module() { + + @Override + public void registerWith(ProteusBuilder builder) { + + // register the default parsers + builder.register(new ViewParser()); + builder.register(new IncludeParser()); + builder.register(new ViewGroupParser()); + builder.register(new RelativeLayoutParser()); + builder.register(new LinearLayoutParser()); + builder.register(new FrameLayoutParser()); + builder.register(new ScrollViewParser()); + builder.register(new HorizontalScrollViewParser()); + builder.register(new ImageViewParser()); + builder.register(new TextViewParser()); + builder.register(new EditTextParser()); + builder.register(new ButtonParser()); + builder.register(new ImageButtonParser()); + builder.register(new WebViewParser()); + builder.register(new RatingBarParser()); + builder.register(new CheckBoxParser()); + builder.register(new ProgressBarParser()); + builder.register(new HorizontalProgressBarParser()); + + // register the default functions + builder.register(Function.DATE); + builder.register(Function.FORMAT); + builder.register(Function.JOIN); + builder.register(Function.NUMBER); + + builder.register(Function.ADD); + builder.register(Function.SUBTRACT); + builder.register(Function.MULTIPLY); + builder.register(Function.DIVIDE); + builder.register(Function.MODULO); + + builder.register(Function.AND); + builder.register(Function.OR); + + builder.register(Function.NOT); + + builder.register(Function.EQUALS); + builder.register(Function.LESS_THAN); + builder.register(Function.GREATER_THAN); + builder.register(Function.LESS_THAN_OR_EQUALS); + builder.register(Function.GREATER_THAN_OR_EQUALS); + + builder.register(Function.TERNARY); + + builder.register(Function.CHAR_AT); + builder.register(Function.CONTAINS); + builder.register(Function.IS_EMPTY); + builder.register(Function.LENGTH); + builder.register(Function.TRIM); + + builder.register(Function.MAX); + builder.register(Function.MIN); + + builder.register(Function.SLICE); } - - public ProteusBuilder register(@NonNull String type, @NonNull Map processors) { - Map map = getExtraAttributeProcessors(type); - map.putAll(processors); - return this; + }; + + private static final int ID = -1; + private Map> processors = new LinkedHashMap<>(); + private Map parsers = new LinkedHashMap<>(); + private HashMap functions = new HashMap<>(); + + public ProteusBuilder() { + DEFAULT_MODULE.registerWith(this); + } + + public ProteusBuilder register(@NonNull String type, @NonNull Map processors) { + Map map = getExtraAttributeProcessors(type); + map.putAll(processors); + return this; + } + + public ProteusBuilder register(@NonNull String type, @NonNull String name, @NonNull AttributeProcessor processor) { + Map map = getExtraAttributeProcessors(type); + map.put(name, processor); + return this; + } + + public ProteusBuilder register(@NonNull ViewTypeParser parser) { + String parentType = parser.getParentType(); + if (parentType != null && !parsers.containsKey(parentType)) { + throw new IllegalStateException(parentType + " is not a registered type parser"); } - - public ProteusBuilder register(@NonNull String type, @NonNull String name, @NonNull AttributeProcessor processor) { - Map map = getExtraAttributeProcessors(type); - map.put(name, processor); - return this; + parsers.put(parser.getType(), parser); + return this; + } + + public ProteusBuilder register(@NonNull Function function) { + functions.put(function.getName(), function); + return this; + } + + public ProteusBuilder register(@NonNull Module module) { + module.registerWith(this); + return this; + } + + @Nullable + public ViewTypeParser get(@NonNull String type) { + return parsers.get(type); + } + + public Proteus build() { + Map types = new HashMap<>(); + for (Map.Entry entry : parsers.entrySet()) { + types.put(entry.getKey(), prepare(entry.getValue())); } - - public ProteusBuilder register(@NonNull ViewTypeParser parser) { - String parentType = parser.getParentType(); - if (parentType != null && !parsers.containsKey(parentType)) { - throw new IllegalStateException(parentType + " is not a registered type parser"); - } - parsers.put(parser.getType(), parser); - return this; + return new Proteus(types, functions); + } + + protected Proteus.Type prepare(ViewTypeParser parser) { + String name = parser.getType(); + ViewTypeParser parent = parsers.get(parser.getParentType()); + Map extras = this.processors.get(name); + + //noinspection unchecked + return new Proteus.Type(ID, name, parser, parser.prepare(parent, extras)); + } + + protected Map getExtraAttributeProcessors(String type) { + Map map = this.processors.get(type); + if (map == null) { + map = new LinkedHashMap<>(); + this.processors.put(type, map); } + return map; + } - public ProteusBuilder register(@NonNull Function function) { - functions.put(function.getName(), function); - return this; - } + public interface Module { - public ProteusBuilder register(@NonNull Module module) { - module.registerWith(this); - return this; - } - - @Nullable - public ViewTypeParser get(@NonNull String type) { - return parsers.get(type); - } - - public Proteus build() { - Map types = new HashMap<>(); - for (Map.Entry entry : parsers.entrySet()) { - types.put(entry.getKey(), prepare(entry.getValue())); - } - return new Proteus(types, functions); - } - - protected Proteus.Type prepare(ViewTypeParser parser) { - String name = parser.getType(); - ViewTypeParser parent = parsers.get(parser.getParentType()); - Map extras = this.processors.get(name); - - //noinspection unchecked - return new Proteus.Type(ID, name, parser, parser.prepare(parent, extras)); - } - - protected Map getExtraAttributeProcessors(String type) { - Map map = this.processors.get(type); - if (map == null) { - map = new LinkedHashMap<>(); - this.processors.put(type, map); - } - return map; - } - - public interface Module { - - /** - * @param builder - */ - void registerWith(ProteusBuilder builder); + /** + * @param builder + */ + void registerWith(ProteusBuilder builder); - } + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusConstants.java b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusConstants.java index e165ebb2..c61d8a3b 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusConstants.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusConstants.java @@ -23,29 +23,29 @@ */ public class ProteusConstants { - public static final String TYPE = "type"; - public static final String LAYOUT = "layout"; + public static final String TYPE = "type"; + public static final String LAYOUT = "layout"; - public static final String DATA = "data"; - public static final String COLLECTION = "collection"; + public static final String DATA = "data"; + public static final String COLLECTION = "collection"; - public static final String DATA_NULL = "null"; + public static final String DATA_NULL = "null"; - public static final String STYLE_DELIMITER = "\\."; + public static final String STYLE_DELIMITER = "\\."; - public static final String EMPTY = ""; + public static final String EMPTY = ""; - public static final Primitive EMPTY_STRING = new Primitive(EMPTY); - public static final Primitive TRUE = new Primitive(true); - public static final Primitive FALSE = new Primitive(false); + public static final Primitive EMPTY_STRING = new Primitive(EMPTY); + public static final Primitive TRUE = new Primitive(true); + public static final Primitive FALSE = new Primitive(false); - private static boolean isLoggingEnabled = false; + private static boolean isLoggingEnabled = false; - public static void setIsLoggingEnabled(boolean isLoggingEnabled) { - ProteusConstants.isLoggingEnabled = isLoggingEnabled; - } + public static void setIsLoggingEnabled(boolean isLoggingEnabled) { + ProteusConstants.isLoggingEnabled = isLoggingEnabled; + } - public static boolean isLoggingEnabled() { - return ProteusConstants.isLoggingEnabled; - } + public static boolean isLoggingEnabled() { + return ProteusConstants.isLoggingEnabled; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusContext.java b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusContext.java index f32828c6..d64e0a61 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusContext.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusContext.java @@ -34,137 +34,137 @@ public class ProteusContext extends ContextWrapper { - @NonNull - private final ProteusResources resources; - - @Nullable - private final ProteusLayoutInflater.Callback callback; - - @Nullable - private final ProteusLayoutInflater.ImageLoader loader; - - private ProteusLayoutInflater inflater; - - ProteusContext(Context base, @NonNull ProteusResources resources, - @Nullable ProteusLayoutInflater.ImageLoader loader, - @Nullable ProteusLayoutInflater.Callback callback) { - super(base); - this.callback = callback; - this.loader = loader; - this.resources = resources; + @NonNull + private final ProteusResources resources; + + @Nullable + private final ProteusLayoutInflater.Callback callback; + + @Nullable + private final ProteusLayoutInflater.ImageLoader loader; + + private ProteusLayoutInflater inflater; + + ProteusContext(Context base, @NonNull ProteusResources resources, + @Nullable ProteusLayoutInflater.ImageLoader loader, + @Nullable ProteusLayoutInflater.Callback callback) { + super(base); + this.callback = callback; + this.loader = loader; + this.resources = resources; + } + + @Nullable + public ProteusLayoutInflater.Callback getCallback() { + return callback; + } + + @NonNull + public FunctionManager getFunctionManager() { + return resources.getFunctionManager(); + } + + @NonNull + public Function getFunction(@NonNull String name) { + return resources.getFunction(name); + } + + @Nullable + public Layout getLayout(@NonNull String name) { + return resources.getLayout(name); + } + + @Nullable + public ProteusLayoutInflater.ImageLoader getLoader() { + return loader; + } + + @NonNull + public ProteusLayoutInflater getInflater(@NonNull IdGenerator idGenerator) { + if (null == this.inflater) { + this.inflater = new SimpleLayoutInflater(this, idGenerator); } + return this.inflater; + } + + @NonNull + public ProteusLayoutInflater getInflater() { + return getInflater(new SimpleIdGenerator()); + } + + @Nullable + public ViewTypeParser getParser(String type) { + return resources.getParsers().get(type); + } + + @NonNull + public ProteusResources getProteusResources() { + return resources; + } + + @Nullable + public Map getStyle(String name) { + return resources.getStyle(name); + } + + /** + * Builder + * + * @author adityasharat + */ + public static class Builder { - @Nullable - public ProteusLayoutInflater.Callback getCallback() { - return callback; - } + @NonNull + private final Context base; @NonNull - public FunctionManager getFunctionManager() { - return resources.getFunctionManager(); - } + private final FunctionManager functionManager; @NonNull - public Function getFunction(@NonNull String name) { - return resources.getFunction(name); - } + private final Map parsers; @Nullable - public Layout getLayout(@NonNull String name) { - return resources.getLayout(name); - } + private ProteusLayoutInflater.ImageLoader loader; @Nullable - public ProteusLayoutInflater.ImageLoader getLoader() { - return loader; - } + private ProteusLayoutInflater.Callback callback; - @NonNull - public ProteusLayoutInflater getInflater(@NonNull IdGenerator idGenerator) { - if (null == this.inflater) { - this.inflater = new SimpleLayoutInflater(this, idGenerator); - } - return this.inflater; - } - - @NonNull - public ProteusLayoutInflater getInflater() { - return getInflater(new SimpleIdGenerator()); - } + @Nullable + private LayoutManager layoutManager; @Nullable - public ViewTypeParser getParser(String type) { - return resources.getParsers().get(type); - } + private StyleManager styleManager; - @NonNull - public ProteusResources getProteusResources() { - return resources; + Builder(@NonNull Context context, @NonNull Map parsers, @NonNull FunctionManager functionManager) { + this.base = context; + this.parsers = parsers; + this.functionManager = functionManager; } - @Nullable - public Map getStyle(String name) { - return resources.getStyle(name); + public Builder setImageLoader(@Nullable ProteusLayoutInflater.ImageLoader loader) { + this.loader = loader; + return this; } - /** - * Builder - * - * @author adityasharat - */ - public static class Builder { - - @NonNull - private final Context base; - - @NonNull - private final FunctionManager functionManager; - - @NonNull - private final Map parsers; - - @Nullable - private ProteusLayoutInflater.ImageLoader loader; - - @Nullable - private ProteusLayoutInflater.Callback callback; - - @Nullable - private LayoutManager layoutManager; - - @Nullable - private StyleManager styleManager; - - Builder(@NonNull Context context, @NonNull Map parsers, @NonNull FunctionManager functionManager) { - this.base = context; - this.parsers = parsers; - this.functionManager = functionManager; - } - - public Builder setImageLoader(@Nullable ProteusLayoutInflater.ImageLoader loader) { - this.loader = loader; - return this; - } - - public Builder setCallback(@Nullable ProteusLayoutInflater.Callback callback) { - this.callback = callback; - return this; - } - - public Builder setLayoutManager(@Nullable LayoutManager layoutManager) { - this.layoutManager = layoutManager; - return this; - } + public Builder setCallback(@Nullable ProteusLayoutInflater.Callback callback) { + this.callback = callback; + return this; + } - public Builder setStyleManager(@Nullable StyleManager styleManager) { - this.styleManager = styleManager; - return this; - } + public Builder setLayoutManager(@Nullable LayoutManager layoutManager) { + this.layoutManager = layoutManager; + return this; + } - public ProteusContext build() { - ProteusResources resources = new ProteusResources(parsers, layoutManager, functionManager, styleManager); - return new ProteusContext(base, resources, loader, callback); - } + public Builder setStyleManager(@Nullable StyleManager styleManager) { + this.styleManager = styleManager; + return this; + } + public ProteusContext build() { + ProteusResources resources = new ProteusResources(parsers, layoutManager, functionManager, styleManager); + return new ProteusContext(base, resources, loader, callback); } + + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusContextWrapper.java b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusContextWrapper.java index b75e94be..6d9160cd 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusContextWrapper.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusContextWrapper.java @@ -29,7 +29,7 @@ public class ProteusContextWrapper extends ProteusContext { - public ProteusContextWrapper(ProteusContext context) { - super(context, context.getProteusResources(), context.getLoader(), context.getCallback()); - } + public ProteusContextWrapper(ProteusContext context) { + super(context, context.getProteusResources(), context.getLoader(), context.getCallback()); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusLayoutInflater.java b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusLayoutInflater.java index 0532014e..d8a85c8e 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusLayoutInflater.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusLayoutInflater.java @@ -32,139 +32,139 @@ */ public interface ProteusLayoutInflater { - /** - * This methods inflates a {@link ProteusView} - * - * @param layout The {@link Layout} which defines the layout for the {@link View} to be inflated. - * @param data The {@link ObjectValue} which will be used to replace bindings with values in the {@link View}. - * @param parent The intended parent view for the {@link View} that will be inflated. - * @param dataIndex An index of data, if it is associated with some index of an array. Pass 0 by default. - * @return An native android view - */ - @NonNull - ProteusView inflate(@NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex); - - /** - * This methods inflates a {@link ProteusView} - * - * @param layout The {@link Layout} which defines the layout for the {@link View} to be inflated. - * @param data The {@link ObjectValue} which will be used to replace bindings with values in the {@link View}. - * @param dataIndex An index of data, if it is associated with some index of an array. Pass 0 by default. - * @return An native android view - */ - @NonNull - ProteusView inflate(@NonNull Layout layout, @NonNull ObjectValue data, int dataIndex); - - /** - * This methods inflates a {@link ProteusView} - * - * @param layout The {@link Layout} which defines the layout for the {@link View} to be inflated. - * @param data The {@link ObjectValue} which will be used to replace bindings with values in the {@link View}. - * @return An native android view - */ - @NonNull - ProteusView inflate(@NonNull Layout layout, @NonNull ObjectValue data); - - /** - * This methods inflates a {@link ProteusView} - * - * @param name The name of the layout to be inflated - * @param data The {@link ObjectValue} which will be used to replace bindings with values in the {@link View}. - * @param parent The intended parent view for the {@link View} that will be inflated. - * @param dataIndex An index of data, if it is associated with some index of an array. Pass 0 by default. - * @return An native android view - */ - @NonNull - ProteusView inflate(@NonNull String name, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex); + /** + * This methods inflates a {@link ProteusView} + * + * @param layout The {@link Layout} which defines the layout for the {@link View} to be inflated. + * @param data The {@link ObjectValue} which will be used to replace bindings with values in the {@link View}. + * @param parent The intended parent view for the {@link View} that will be inflated. + * @param dataIndex An index of data, if it is associated with some index of an array. Pass 0 by default. + * @return An native android view + */ + @NonNull + ProteusView inflate(@NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex); + + /** + * This methods inflates a {@link ProteusView} + * + * @param layout The {@link Layout} which defines the layout for the {@link View} to be inflated. + * @param data The {@link ObjectValue} which will be used to replace bindings with values in the {@link View}. + * @param dataIndex An index of data, if it is associated with some index of an array. Pass 0 by default. + * @return An native android view + */ + @NonNull + ProteusView inflate(@NonNull Layout layout, @NonNull ObjectValue data, int dataIndex); + + /** + * This methods inflates a {@link ProteusView} + * + * @param layout The {@link Layout} which defines the layout for the {@link View} to be inflated. + * @param data The {@link ObjectValue} which will be used to replace bindings with values in the {@link View}. + * @return An native android view + */ + @NonNull + ProteusView inflate(@NonNull Layout layout, @NonNull ObjectValue data); + + /** + * This methods inflates a {@link ProteusView} + * + * @param name The name of the layout to be inflated + * @param data The {@link ObjectValue} which will be used to replace bindings with values in the {@link View}. + * @param parent The intended parent view for the {@link View} that will be inflated. + * @param dataIndex An index of data, if it is associated with some index of an array. Pass 0 by default. + * @return An native android view + */ + @NonNull + ProteusView inflate(@NonNull String name, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex); + + /** + * This methods inflates a {@link ProteusView} + * + * @param name The name of the layout to be inflated + * @param data The {@link ObjectValue} which will be used to replace bindings with values in the {@link View}. + * @param dataIndex An index of data, if it is associated with some index of an array. Pass 0 by default. + * @return An native android view + */ + @NonNull + ProteusView inflate(@NonNull String name, @NonNull ObjectValue data, int dataIndex); + + /** + * This methods inflates a {@link ProteusView} + * + * @param name The name of the layout to be inflated + * @param data The {@link ObjectValue} which will be used to replace bindings with values in the {@link View}. + * @return An native android view + */ + @NonNull + ProteusView inflate(@NonNull String name, @NonNull ObjectValue data); + + /** + * Returns the {@link ViewTypeParser} for the specified view type. + * + * @param type The name of the view type. + * @return The {@link ViewTypeParser} associated to the specified view type + */ + @Nullable + ViewTypeParser getParser(@NonNull String type); + + /** + * Give the View ID for this string. This will generally be given by the instance of ID Generator + * which will be available with the Layout Inflater. + * This is similar to R.id auto generated + * + * @return int value for this id. This will never be -1. + */ + int getUniqueViewId(@NonNull String id); + + /** + * All consumers of this should ensure that they save the instance state of + * the ID generator along with the activity/fragment and resume it when the + * Layout Inflater is being re-initialized + * + * @return Returns the Id Generator for this Layout Inflater + */ + @NonNull + IdGenerator getIdGenerator(); + + /** + * The Layout Inflaters callback interface + */ + interface Callback { /** - * This methods inflates a {@link ProteusView} + * This call back is called when the inflater encounters a view type which is no registered with it. * - * @param name The name of the layout to be inflated - * @param data The {@link ObjectValue} which will be used to replace bindings with values in the {@link View}. - * @param dataIndex An index of data, if it is associated with some index of an array. Pass 0 by default. - * @return An native android view + * @param context The Proteus Context + * @param type The type of the layout + * @param layout The layout + * @param data The data which should be bound to this view + * @param index The data index + * @return The native view to be returned */ @NonNull - ProteusView inflate(@NonNull String name, @NonNull ObjectValue data, int dataIndex); + ProteusView onUnknownViewType(ProteusContext context, String type, Layout layout, ObjectValue data, int index); /** - * This methods inflates a {@link ProteusView} + * This callback is called when any user interaction occurs on a view * - * @param name The name of the layout to be inflated - * @param data The {@link ObjectValue} which will be used to replace bindings with values in the {@link View}. - * @return An native android view + * @param event The Event type + * @param value Value set to the event attribute + * @param view The view that triggered the event */ - @NonNull - ProteusView inflate(@NonNull String name, @NonNull ObjectValue data); + void onEvent(String event, Value value, ProteusView view); - /** - * Returns the {@link ViewTypeParser} for the specified view type. - * - * @param type The name of the view type. - * @return The {@link ViewTypeParser} associated to the specified view type - */ - @Nullable - ViewTypeParser getParser(@NonNull String type); + } + /** + * Used for loading drawables/images/bitmaps asynchronously + */ + interface ImageLoader { /** - * Give the View ID for this string. This will generally be given by the instance of ID Generator - * which will be available with the Layout Inflater. - * This is similar to R.id auto generated + * Useful for asynchronous download of bitmap. * - * @return int value for this id. This will never be -1. - */ - int getUniqueViewId(@NonNull String id); - - /** - * All consumers of this should ensure that they save the instance state of - * the ID generator along with the activity/fragment and resume it when the - * Layout Inflater is being re-initialized - * - * @return Returns the Id Generator for this Layout Inflater - */ - @NonNull - IdGenerator getIdGenerator(); - - /** - * The Layout Inflaters callback interface - */ - interface Callback { - - /** - * This call back is called when the inflater encounters a view type which is no registered with it. - * - * @param context The Proteus Context - * @param type The type of the layout - * @param layout The layout - * @param data The data which should be bound to this view - * @param index The data index - * @return The native view to be returned - */ - @NonNull - ProteusView onUnknownViewType(ProteusContext context, String type, Layout layout, ObjectValue data, int index); - - /** - * This callback is called when any user interaction occurs on a view - * - * @param event The Event type - * @param value Value set to the event attribute - * @param view The view that triggered the event - */ - void onEvent(String event, Value value, ProteusView view); - - } - - /** - * Used for loading drawables/images/bitmaps asynchronously + * @param url the url for the drawable/bitmap/image + * @param callback the callback to set the drawable/bitmap */ - interface ImageLoader { - /** - * Useful for asynchronous download of bitmap. - * - * @param url the url for the drawable/bitmap/image - * @param callback the callback to set the drawable/bitmap - */ - void getBitmap(ProteusView view, String url, DrawableValue.AsyncCallback callback); - } + void getBitmap(ProteusView view, String url, DrawableValue.AsyncCallback callback); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusResources.java b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusResources.java index 1978a931..a7640467 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusResources.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusResources.java @@ -32,48 +32,48 @@ public class ProteusResources { - @NonNull - private final Map parsers; - - @Nullable - private final LayoutManager layoutManager; - - @NonNull - private final FunctionManager functionManager; - - @Nullable - private final StyleManager styleManager; - - ProteusResources(@NonNull Map parsers, @Nullable LayoutManager layoutManager, - @NonNull FunctionManager functionManager, @Nullable StyleManager styleManager) { - this.parsers = parsers; - this.layoutManager = layoutManager; - this.functionManager = functionManager; - this.styleManager = styleManager; - } - - @NonNull - public FunctionManager getFunctionManager() { - return this.functionManager; - } - - @NonNull - public Function getFunction(@NonNull String name) { - return functionManager.get(name); - } - - @Nullable - public Layout getLayout(@NonNull String name) { - return null != layoutManager ? layoutManager.get(name) : null; - } - - @NonNull - public Map getParsers() { - return parsers; - } - - @Nullable - public Map getStyle(String name) { - return null != styleManager ? styleManager.get(name) : null; - } + @NonNull + private final Map parsers; + + @Nullable + private final LayoutManager layoutManager; + + @NonNull + private final FunctionManager functionManager; + + @Nullable + private final StyleManager styleManager; + + ProteusResources(@NonNull Map parsers, @Nullable LayoutManager layoutManager, + @NonNull FunctionManager functionManager, @Nullable StyleManager styleManager) { + this.parsers = parsers; + this.layoutManager = layoutManager; + this.functionManager = functionManager; + this.styleManager = styleManager; + } + + @NonNull + public FunctionManager getFunctionManager() { + return this.functionManager; + } + + @NonNull + public Function getFunction(@NonNull String name) { + return functionManager.get(name); + } + + @Nullable + public Layout getLayout(@NonNull String name) { + return null != layoutManager ? layoutManager.get(name) : null; + } + + @NonNull + public Map getParsers() { + return parsers; + } + + @Nullable + public Map getStyle(String name) { + return null != styleManager ? styleManager.get(name) : null; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusView.java b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusView.java index 825bc106..46876ad6 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusView.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/ProteusView.java @@ -37,85 +37,85 @@ */ public interface ProteusView { + /** + * @return The View Manager of this Proteus View. + */ + Manager getViewManager(); + + /** + * @param manager Sets a View Manager on this View. + */ + void setViewManager(@NonNull Manager manager); + + /** + * @return The interface as an Android native View. + */ + @NonNull + View getAsView(); + + /** + * Manager + * + * @author aditya.sharat + */ + interface Manager { + + /** + * Update the {@link View} with new data. + * + * @param data New data for the view + */ + void update(@Nullable ObjectValue data); + + /** + * Look for a child view with the given id. If this view has the given + * id, return this view. Similar to {@link View#findViewById(int)}. Since + * Proteus is a runtime inflater, layouts use String ids instead of int and it + * generates unique int ids using the {@link IdGenerator}. + * + * @param id The string id to search for. + * @return The view that has the given id in the hierarchy or null + */ + @Nullable + View findViewById(@NonNull String id); + /** - * @return The View Manager of this Proteus View. + * @return The Proteus Context associated with this Manager. */ - Manager getViewManager(); + @NonNull + ProteusContext getContext(); /** - * @param manager Sets a View Manager on this View. + * @return The Layout of View which is hosting this manager. */ - void setViewManager(@NonNull Manager manager); + @NonNull + Layout getLayout(); /** - * @return The interface as an Android native View. + * @return The Data Context of the view which is hosting this manager. */ @NonNull - View getAsView(); + DataContext getDataContext(); + + /** + * Returns this proteus view's extras. + * + * @return the Object stored in this view as a extra, or {@code null} if not set + * @see #setExtras(Object) + */ + @Nullable + Object getExtras(); /** - * Manager + * Sets the extra associated with this view. A extra can be used to mark a view in its hierarchy + * and does not have to be unique within the hierarchy. Extras can also be used to store data + * within a proteus view without resorting to another data structure. + * It is similar to {@link View#setTag(Object)} * - * @author aditya.sharat + * @param extras The object to set as the extra. + * @see #setExtras(Object) */ - interface Manager { - - /** - * Update the {@link View} with new data. - * - * @param data New data for the view - */ - void update(@Nullable ObjectValue data); - - /** - * Look for a child view with the given id. If this view has the given - * id, return this view. Similar to {@link View#findViewById(int)}. Since - * Proteus is a runtime inflater, layouts use String ids instead of int and it - * generates unique int ids using the {@link IdGenerator}. - * - * @param id The string id to search for. - * @return The view that has the given id in the hierarchy or null - */ - @Nullable - View findViewById(@NonNull String id); - - /** - * @return The Proteus Context associated with this Manager. - */ - @NonNull - ProteusContext getContext(); - - /** - * @return The Layout of View which is hosting this manager. - */ - @NonNull - Layout getLayout(); - - /** - * @return The Data Context of the view which is hosting this manager. - */ - @NonNull - DataContext getDataContext(); - - /** - * Returns this proteus view's extras. - * - * @return the Object stored in this view as a extra, or {@code null} if not set - * @see #setExtras(Object) - */ - @Nullable - Object getExtras(); - - /** - * Sets the extra associated with this view. A extra can be used to mark a view in its hierarchy - * and does not have to be unique within the hierarchy. Extras can also be used to store data - * within a proteus view without resorting to another data structure. - * It is similar to {@link View#setTag(Object)} - * - * @param extras The object to set as the extra. - * @see #setExtras(Object) - */ - void setExtras(@Nullable Object extras); - - } + void setExtras(@Nullable Object extras); + + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/SimpleIdGenerator.java b/proteus-core/src/main/java/com/flipkart/android/proteus/SimpleIdGenerator.java index 12a4b72e..aa8ade6e 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/SimpleIdGenerator.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/SimpleIdGenerator.java @@ -32,93 +32,93 @@ * @author aditya.sharat */ public class SimpleIdGenerator implements IdGenerator { - public final static Parcelable.Creator CREATOR = new Creator() { - @Override - public SimpleIdGenerator createFromParcel(Parcel source) { - return new SimpleIdGenerator(source); - } - - @Override - public SimpleIdGenerator[] newArray(int size) { - return new SimpleIdGenerator[size]; - } - }; - private final HashMap idMap = new HashMap<>(); - private final AtomicInteger sNextGeneratedId; - - public SimpleIdGenerator() { - sNextGeneratedId = new AtomicInteger(1); - } - - public SimpleIdGenerator(Parcel source) { - sNextGeneratedId = new AtomicInteger(source.readInt()); - source.readMap(idMap, null); - } - - /** - * Flatten this object in to a Parcel. - * - * @param dest The Parcel in which the object should be written. - * @param flags Additional flags about how the object should be written. - * May be 0 or {@link #PARCELABLE_WRITE_RETURN_VALUE}. - */ + public final static Parcelable.Creator CREATOR = new Creator() { @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(sNextGeneratedId.get()); - dest.writeMap(idMap); + public SimpleIdGenerator createFromParcel(Parcel source) { + return new SimpleIdGenerator(source); } - /** - * Generates and returns a unique id, for the given key. - * If key exists, returns old value. - * Ensure that all - * - * @param idKey - * @return a unique ID integer for use with {@link android.view.View#setId(int)}. - */ @Override - public synchronized int getUnique(String idKey) { - Integer existingId = idMap.get(idKey); - if (existingId == null) { - int newId = generateViewId(); - idMap.put(idKey, newId); - existingId = newId; - } - return existingId; + public SimpleIdGenerator[] newArray(int size) { + return new SimpleIdGenerator[size]; } + }; + private final HashMap idMap = new HashMap<>(); + private final AtomicInteger sNextGeneratedId; - /** - * Taken from Android View Source code API 17+ - *

- * Generate a value suitable for use. - * This value will not collide with ID values generated at inflate time by aapt for R.id. - * - * @return a generated ID value - */ - private int generateViewId() { - for (; ; ) { - final int result = sNextGeneratedId.get(); + public SimpleIdGenerator() { + sNextGeneratedId = new AtomicInteger(1); + } - // aapt-generated IDs have the high byte nonzero; clamp to the range under that. - int newValue = result + 1; - if (newValue > 0x00FFFFFF) { - newValue = 1; // Roll over to 1, not 0. - } - if (sNextGeneratedId.compareAndSet(result, newValue)) { - return result; - } - } + public SimpleIdGenerator(Parcel source) { + sNextGeneratedId = new AtomicInteger(source.readInt()); + source.readMap(idMap, null); + } + + /** + * Flatten this object in to a Parcel. + * + * @param dest The Parcel in which the object should be written. + * @param flags Additional flags about how the object should be written. + * May be 0 or {@link #PARCELABLE_WRITE_RETURN_VALUE}. + */ + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(sNextGeneratedId.get()); + dest.writeMap(idMap); + } + + /** + * Generates and returns a unique id, for the given key. + * If key exists, returns old value. + * Ensure that all + * + * @param idKey + * @return a unique ID integer for use with {@link android.view.View#setId(int)}. + */ + @Override + public synchronized int getUnique(String idKey) { + Integer existingId = idMap.get(idKey); + if (existingId == null) { + int newId = generateViewId(); + idMap.put(idKey, newId); + existingId = newId; } + return existingId; + } - /** - * Describe the kinds of special objects contained in this Parcelable's - * marshalled representation. - * - * @return a bitmask indicating the set of special object types marshalled - * by the Parcelable. - */ - @Override - public int describeContents() { - return 0; + /** + * Taken from Android View Source code API 17+ + *

+ * Generate a value suitable for use. + * This value will not collide with ID values generated at inflate time by aapt for R.id. + * + * @return a generated ID value + */ + private int generateViewId() { + for (; ; ) { + final int result = sNextGeneratedId.get(); + + // aapt-generated IDs have the high byte nonzero; clamp to the range under that. + int newValue = result + 1; + if (newValue > 0x00FFFFFF) { + newValue = 1; // Roll over to 1, not 0. + } + if (sNextGeneratedId.compareAndSet(result, newValue)) { + return result; + } } + } + + /** + * Describe the kinds of special objects contained in this Parcelable's + * marshalled representation. + * + * @return a bitmask indicating the set of special object types marshalled + * by the Parcelable. + */ + @Override + public int describeContents() { + return 0; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/SimpleLayoutInflater.java b/proteus-core/src/main/java/com/flipkart/android/proteus/SimpleLayoutInflater.java index ae172e16..6d0cc746 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/SimpleLayoutInflater.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/SimpleLayoutInflater.java @@ -34,157 +34,157 @@ */ public class SimpleLayoutInflater implements ProteusLayoutInflater { - private static final String TAG = "SimpleLayoutInflater"; - - @NonNull - protected final ProteusContext context; - - @NonNull - protected final IdGenerator idGenerator; - - SimpleLayoutInflater(@NonNull ProteusContext context, @NonNull IdGenerator idGenerator) { - this.context = context; - this.idGenerator = idGenerator; + private static final String TAG = "SimpleLayoutInflater"; + + @NonNull + protected final ProteusContext context; + + @NonNull + protected final IdGenerator idGenerator; + + SimpleLayoutInflater(@NonNull ProteusContext context, @NonNull IdGenerator idGenerator) { + this.context = context; + this.idGenerator = idGenerator; + } + + @Override + @Nullable + public ViewTypeParser getParser(@NonNull String type) { + return context.getParser(type); + } + + @NonNull + @Override + public ProteusView inflate(@NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { + + /* + * Get the the view type parser for this layout type + */ + final ViewTypeParser parser = getParser(layout.type); + if (parser == null) { + /* + * If parser is not registered ask the application land for the view + */ + return onUnknownViewEncountered(layout.type, layout, data, dataIndex); } - @Override - @Nullable - public ViewTypeParser getParser(@NonNull String type) { - return context.getParser(type); - } + /* + * Create a view of {@code layout.type} + */ + final ProteusView view = createView(parser, layout, data, parent, dataIndex); - @NonNull - @Override - public ProteusView inflate(@NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { - - /* - * Get the the view type parser for this layout type - */ - final ViewTypeParser parser = getParser(layout.type); - if (parser == null) { - /* - * If parser is not registered ask the application land for the view - */ - return onUnknownViewEncountered(layout.type, layout, data, dataIndex); - } - - /* - * Create a view of {@code layout.type} - */ - final ProteusView view = createView(parser, layout, data, parent, dataIndex); - - if (view.getViewManager() == null) { - - /* - * Do post creation logic - */ - onAfterCreateView(parser, view, parent, dataIndex); - - /* - * Create View Manager for {@code layout.type} - */ - final ProteusView.Manager viewManager = createViewManager(parser, view, layout, data, parent, dataIndex); - - /* - * Set the View Manager on the view. - */ - view.setViewManager(viewManager); - } - - /* - * Handle each attribute and set it on the view. - */ - if (layout.attributes != null) { - Iterator iterator = layout.attributes.iterator(); - Layout.Attribute attribute; - while (iterator.hasNext()) { - attribute = iterator.next(); - handleAttribute(parser, view, attribute.id, attribute.value); - } - } - - return view; - } + if (view.getViewManager() == null) { - @NonNull - @Override - public ProteusView inflate(@NonNull Layout layout, @NonNull ObjectValue data, int dataIndex) { - return inflate(layout, data, null, dataIndex); - } + /* + * Do post creation logic + */ + onAfterCreateView(parser, view, parent, dataIndex); - @NonNull - @Override - public ProteusView inflate(@NonNull Layout layout, @NonNull ObjectValue data) { - return inflate(layout, data, null, -1); - } + /* + * Create View Manager for {@code layout.type} + */ + final ProteusView.Manager viewManager = createViewManager(parser, view, layout, data, parent, dataIndex); - @NonNull - @Override - public ProteusView inflate(@NonNull String name, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { - Layout layout = context.getLayout(name); - if (null == layout) { - throw new ProteusInflateException("layout : '" + name + "' not found"); - } - return inflate(layout, data, parent, dataIndex); + /* + * Set the View Manager on the view. + */ + view.setViewManager(viewManager); } - @NonNull - @Override - public ProteusView inflate(@NonNull String name, @NonNull ObjectValue data, int dataIndex) { - return inflate(name, data, null, dataIndex); + /* + * Handle each attribute and set it on the view. + */ + if (layout.attributes != null) { + Iterator iterator = layout.attributes.iterator(); + Layout.Attribute attribute; + while (iterator.hasNext()) { + attribute = iterator.next(); + handleAttribute(parser, view, attribute.id, attribute.value); + } } - @NonNull - @Override - public ProteusView inflate(@NonNull String name, @NonNull ObjectValue data) { - return inflate(name, data, null, -1); + return view; + } + + @NonNull + @Override + public ProteusView inflate(@NonNull Layout layout, @NonNull ObjectValue data, int dataIndex) { + return inflate(layout, data, null, dataIndex); + } + + @NonNull + @Override + public ProteusView inflate(@NonNull Layout layout, @NonNull ObjectValue data) { + return inflate(layout, data, null, -1); + } + + @NonNull + @Override + public ProteusView inflate(@NonNull String name, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { + Layout layout = context.getLayout(name); + if (null == layout) { + throw new ProteusInflateException("layout : '" + name + "' not found"); } - - @Override - public int getUniqueViewId(@NonNull String id) { - return idGenerator.getUnique(id); + return inflate(layout, data, parent, dataIndex); + } + + @NonNull + @Override + public ProteusView inflate(@NonNull String name, @NonNull ObjectValue data, int dataIndex) { + return inflate(name, data, null, dataIndex); + } + + @NonNull + @Override + public ProteusView inflate(@NonNull String name, @NonNull ObjectValue data) { + return inflate(name, data, null, -1); + } + + @Override + public int getUniqueViewId(@NonNull String id) { + return idGenerator.getUnique(id); + } + + @NonNull + @Override + public IdGenerator getIdGenerator() { + return idGenerator; + } + + protected ProteusView createView(@NonNull ViewTypeParser parser, @NonNull Layout layout, @NonNull ObjectValue data, + @Nullable ViewGroup parent, int dataIndex) { + return parser.createView(context, layout, data, parent, dataIndex); + } + + protected ProteusView.Manager createViewManager(@NonNull ViewTypeParser parser, @NonNull ProteusView view, @NonNull Layout layout, + @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { + return parser.createViewManager(context, view, layout, data, parser, parent, dataIndex); + } + + protected void onAfterCreateView(@NonNull ViewTypeParser parser, @NonNull ProteusView view, @Nullable ViewGroup parent, int index) { + parser.onAfterCreateView(view, parent, index); + } + + @NonNull + protected ProteusView onUnknownViewEncountered(String type, Layout layout, ObjectValue data, int dataIndex) { + if (ProteusConstants.isLoggingEnabled()) { + Log.d(TAG, "No ViewTypeParser for: " + type); } - - @NonNull - @Override - public IdGenerator getIdGenerator() { - return idGenerator; - } - - protected ProteusView createView(@NonNull ViewTypeParser parser, @NonNull Layout layout, @NonNull ObjectValue data, - @Nullable ViewGroup parent, int dataIndex) { - return parser.createView(context, layout, data, parent, dataIndex); - } - - protected ProteusView.Manager createViewManager(@NonNull ViewTypeParser parser, @NonNull ProteusView view, @NonNull Layout layout, - @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { - return parser.createViewManager(context, view, layout, data, parser, parent, dataIndex); - } - - protected void onAfterCreateView(@NonNull ViewTypeParser parser, @NonNull ProteusView view, @Nullable ViewGroup parent, int index) { - parser.onAfterCreateView(view, parent, index); - } - - @NonNull - protected ProteusView onUnknownViewEncountered(String type, Layout layout, ObjectValue data, int dataIndex) { - if (ProteusConstants.isLoggingEnabled()) { - Log.d(TAG, "No ViewTypeParser for: " + type); - } - if (context.getCallback() != null) { - ProteusView view = context.getCallback().onUnknownViewType(context, type, layout, data, dataIndex); - //noinspection ConstantConditions because we need to throw a ProteusInflateException specifically - if (view == null) { - throw new ProteusInflateException("inflater Callback#onUnknownViewType() must not return null"); - } - } - throw new ProteusInflateException("Layout contains type: 'include' but inflater callback is null"); + if (context.getCallback() != null) { + ProteusView view = context.getCallback().onUnknownViewType(context, type, layout, data, dataIndex); + //noinspection ConstantConditions because we need to throw a ProteusInflateException specifically + if (view == null) { + throw new ProteusInflateException("inflater Callback#onUnknownViewType() must not return null"); + } } + throw new ProteusInflateException("Layout contains type: 'include' but inflater callback is null"); + } - protected boolean handleAttribute(@NonNull ViewTypeParser parser, @NonNull ProteusView view, int attribute, @NonNull Value value) { - if (ProteusConstants.isLoggingEnabled()) { - Log.d(TAG, "Handle '" + attribute + "' : " + value); - } - //noinspection unchecked - return parser.handleAttribute(view.getAsView(), attribute, value); + protected boolean handleAttribute(@NonNull ViewTypeParser parser, @NonNull ProteusView view, int attribute, @NonNull Value value) { + if (ProteusConstants.isLoggingEnabled()) { + Log.d(TAG, "Handle '" + attribute + "' : " + value); } + //noinspection unchecked + return parser.handleAttribute(view.getAsView(), attribute, value); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/StyleManager.java b/proteus-core/src/main/java/com/flipkart/android/proteus/StyleManager.java index 99fb27b9..9bf2fcd9 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/StyleManager.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/StyleManager.java @@ -29,11 +29,11 @@ * @author adityasharat */ public abstract class StyleManager { - @Nullable - protected abstract Styles getStyles(); + @Nullable + protected abstract Styles getStyles(); - @Nullable - public Map get(@NonNull String name) { - return null != getStyles() ? getStyles().get(name) : null; - } + @Nullable + public Map get(@NonNull String name) { + return null != getStyles() ? getStyles().get(name) : null; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/Styles.java b/proteus-core/src/main/java/com/flipkart/android/proteus/Styles.java index 507127c8..27450e83 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/Styles.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/Styles.java @@ -28,11 +28,11 @@ */ public class Styles extends HashMap> { - public Map getStyle(String name) { - return this.get(name); - } + public Map getStyle(String name) { + return this.get(name); + } - public boolean contains(String name) { - return this.containsKey(name); - } + public boolean contains(String name) { + return this.containsKey(name); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/ViewTypeParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/ViewTypeParser.java index 9b2bb187..e2d8c844 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/ViewTypeParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/ViewTypeParser.java @@ -41,308 +41,308 @@ */ public abstract class ViewTypeParser { - private static XmlResourceParser sParser = null; - - @Nullable - public ViewTypeParser parent; - - private AttributeProcessor[] processors = new AttributeProcessor[0]; - - private Map attributes = new HashMap<>(); - - private int offset = 0; - - private AttributeSet attributeSet; - - /** - * @return - */ - @NonNull - public abstract String getType(); - - /** - * @return - */ - @Nullable - public abstract String getParentType(); - - /** - * @param context - * @param layout - * @param data - * @param parent - * @param dataIndex - * @return - */ - @NonNull - public abstract ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, - @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex); - - /** - * @param context - * @param view - * @param layout - * @param data - * @param caller - * @param parent - * @param dataIndex @return - */ - @NonNull - public ProteusView.Manager createViewManager(@NonNull ProteusContext context, @NonNull ProteusView view, - @NonNull Layout layout, @NonNull ObjectValue data, - @Nullable ViewTypeParser caller, @Nullable ViewGroup parent, - int dataIndex) { - if (null != this.parent && caller != this.parent) { - return this.parent.createViewManager(context, view, layout, data, caller, parent, dataIndex); - } else { - DataContext dataContext = createDataContext(context, layout, data, parent, dataIndex); - return new ViewManager(context, caller != null ? caller : this, view.getAsView(), layout, dataContext); - } + private static XmlResourceParser sParser = null; + + @Nullable + public ViewTypeParser parent; + + private AttributeProcessor[] processors = new AttributeProcessor[0]; + + private Map attributes = new HashMap<>(); + + private int offset = 0; + + private AttributeSet attributeSet; + + /** + * @return + */ + @NonNull + public abstract String getType(); + + /** + * @return + */ + @Nullable + public abstract String getParentType(); + + /** + * @param context + * @param layout + * @param data + * @param parent + * @param dataIndex + * @return + */ + @NonNull + public abstract ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, + @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex); + + /** + * @param context + * @param view + * @param layout + * @param data + * @param caller + * @param parent + * @param dataIndex @return + */ + @NonNull + public ProteusView.Manager createViewManager(@NonNull ProteusContext context, @NonNull ProteusView view, + @NonNull Layout layout, @NonNull ObjectValue data, + @Nullable ViewTypeParser caller, @Nullable ViewGroup parent, + int dataIndex) { + if (null != this.parent && caller != this.parent) { + return this.parent.createViewManager(context, view, layout, data, caller, parent, dataIndex); + } else { + DataContext dataContext = createDataContext(context, layout, data, parent, dataIndex); + return new ViewManager(context, caller != null ? caller : this, view.getAsView(), layout, dataContext); } - - /** - * @param context - * @param layout - * @param data - * @param parent - * @param dataIndex - * @return - */ - @NonNull - protected DataContext createDataContext(ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, - @Nullable ViewGroup parent, int dataIndex) { - DataContext dataContext, parentDataContext = null; - Map map = layout.data; - - if (parent instanceof ProteusView) { - parentDataContext = ((ProteusView) parent).getViewManager().getDataContext(); - } - - if (map == null) { - if (parentDataContext == null) { - dataContext = DataContext.create(context, data, dataIndex); - } else { - dataContext = parentDataContext.copy(); - } - } else { - if (parentDataContext == null) { - dataContext = DataContext.create(context, data, dataIndex, map); - } else { - dataContext = parentDataContext.createChild(context, map, dataIndex); - } - } - return dataContext; + } + + /** + * @param context + * @param layout + * @param data + * @param parent + * @param dataIndex + * @return + */ + @NonNull + protected DataContext createDataContext(ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, + @Nullable ViewGroup parent, int dataIndex) { + DataContext dataContext, parentDataContext = null; + Map map = layout.data; + + if (parent instanceof ProteusView) { + parentDataContext = ((ProteusView) parent).getViewManager().getDataContext(); } - /** - * @param view - * @param parent - * @param dataIndex - */ - public void onAfterCreateView(@NonNull ProteusView view, @Nullable ViewGroup parent, int dataIndex) { - View v = view.getAsView(); - if (null == v.getLayoutParams()) { - ViewGroup.LayoutParams layoutParams; - if (parent != null) { - layoutParams = generateDefaultLayoutParams(parent); - } else { - layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); - } - v.setLayoutParams(layoutParams); - } + if (map == null) { + if (parentDataContext == null) { + dataContext = DataContext.create(context, data, dataIndex); + } else { + dataContext = parentDataContext.copy(); + } + } else { + if (parentDataContext == null) { + dataContext = DataContext.create(context, data, dataIndex, map); + } else { + dataContext = parentDataContext.createChild(context, map, dataIndex); + } } - - /** - * - */ - protected abstract void addAttributeProcessors(); - - /** - * @param view - * @param attributeId - * @param value - * @return - */ - public boolean handleAttribute(V view, int attributeId, Value value) { - int position = getPosition(attributeId); - if (position < 0) { - //noinspection unchecked - return null != parent && parent.handleAttribute(view, attributeId, value); - } - AttributeProcessor attributeProcessor = processors[position]; - //noinspection unchecked - attributeProcessor.process(view, value); - return true; + return dataContext; + } + + /** + * @param view + * @param parent + * @param dataIndex + */ + public void onAfterCreateView(@NonNull ProteusView view, @Nullable ViewGroup parent, int dataIndex) { + View v = view.getAsView(); + if (null == v.getLayoutParams()) { + ViewGroup.LayoutParams layoutParams; + if (parent != null) { + layoutParams = generateDefaultLayoutParams(parent); + } else { + layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + } + v.setLayoutParams(layoutParams); } - - /** - * @param view - * @param children - * @return - */ - public boolean handleChildren(V view, Value children) { - //noinspection unchecked - return null != parent && parent.handleChildren(view, children); + } + + /** + * + */ + protected abstract void addAttributeProcessors(); + + /** + * @param view + * @param attributeId + * @param value + * @return + */ + public boolean handleAttribute(V view, int attributeId, Value value) { + int position = getPosition(attributeId); + if (position < 0) { + //noinspection unchecked + return null != parent && parent.handleAttribute(view, attributeId, value); } - - /** - * @param parent - * @param view - * @return - */ - public boolean addView(ProteusView parent, ProteusView view) { - return null != this.parent && this.parent.addView(parent, view); + AttributeProcessor attributeProcessor = processors[position]; + //noinspection unchecked + attributeProcessor.process(view, value); + return true; + } + + /** + * @param view + * @param children + * @return + */ + public boolean handleChildren(V view, Value children) { + //noinspection unchecked + return null != parent && parent.handleChildren(view, children); + } + + /** + * @param parent + * @param view + * @return + */ + public boolean addView(ProteusView parent, ProteusView view) { + return null != this.parent && this.parent.addView(parent, view); + } + + /** + * @param parent + * @param extras + * @return + */ + @NonNull + public AttributeSet prepare(@Nullable ViewTypeParser parent, @Nullable Map> extras) { + this.parent = parent; + this.processors = new AttributeProcessor[0]; + this.attributes = new HashMap<>(); + this.offset = null != parent ? parent.getAttributeSet().getOffset() : 0; + + addAttributeProcessors(); + + if (extras != null) { + addAttributeProcessors(extras); } - /** - * @param parent - * @param extras - * @return - */ - @NonNull - public AttributeSet prepare(@Nullable ViewTypeParser parent, @Nullable Map> extras) { - this.parent = parent; - this.processors = new AttributeProcessor[0]; - this.attributes = new HashMap<>(); - this.offset = null != parent ? parent.getAttributeSet().getOffset() : 0; + this.attributeSet = new AttributeSet(attributes.size() > 0 ? attributes : null, null != parent ? parent.getAttributeSet() : null, processors.length); + return attributeSet; + } + + /** + * @param name + * @return + */ + public int getAttributeId(String name) { + AttributeSet.Attribute attribute = attributeSet.getAttribute(name); + return null != attribute ? attribute.id : -1; + } + + /** + * @return + */ + @NonNull + public AttributeSet getAttributeSet() { + return this.attributeSet; + } + + protected void addAttributeProcessors(@NonNull Map> processors) { + for (Map.Entry> entry : processors.entrySet()) { + addAttributeProcessor(entry.getKey(), entry.getValue()); + } + } - addAttributeProcessors(); + /** + * @param name + * @param processor + */ + protected void addAttributeProcessor(String name, AttributeProcessor processor) { + addAttributeProcessor(processor); + attributes.put(name, new AttributeSet.Attribute(getAttributeId(processors.length - 1), processor)); + } - if (extras != null) { - addAttributeProcessors(extras); - } + private void addAttributeProcessor(AttributeProcessor handler) { + processors = Arrays.copyOf(processors, processors.length + 1); + processors[processors.length - 1] = handler; + } - this.attributeSet = new AttributeSet(attributes.size() > 0 ? attributes : null, null != parent ? parent.getAttributeSet() : null, processors.length); - return attributeSet; - } + private int getOffset() { + return offset; + } - /** - * @param name - * @return - */ - public int getAttributeId(String name) { - AttributeSet.Attribute attribute = attributeSet.getAttribute(name); - return null != attribute ? attribute.id : -1; - } + private int getPosition(int attributeId) { + return attributeId + getOffset(); + } - /** - * @return - */ - @NonNull - public AttributeSet getAttributeSet() { - return this.attributeSet; - } + private int getAttributeId(int position) { + return position - getOffset(); + } - protected void addAttributeProcessors(@NonNull Map> processors) { - for (Map.Entry> entry : processors.entrySet()) { - addAttributeProcessor(entry.getKey(), entry.getValue()); - } - } + private ViewGroup.LayoutParams generateDefaultLayoutParams(@NonNull ViewGroup parent) { /** - * @param name - * @param processor + * This whole method is a hack! To generate layout params, since no other way exists. + * Refer : http://stackoverflow.com/questions/7018267/generating-a-layoutparams-based-on-the-type-of-parent */ - protected void addAttributeProcessor(String name, AttributeProcessor processor) { - addAttributeProcessor(processor); - attributes.put(name, new AttributeSet.Attribute(getAttributeId(processors.length - 1), processor)); - } - - private void addAttributeProcessor(AttributeProcessor handler) { - processors = Arrays.copyOf(processors, processors.length + 1); - processors[processors.length - 1] = handler; - } - - private int getOffset() { - return offset; - } - - private int getPosition(int attributeId) { - return attributeId + getOffset(); - } - - private int getAttributeId(int position) { - return position - getOffset(); - } - - private ViewGroup.LayoutParams generateDefaultLayoutParams(@NonNull ViewGroup parent) { - - /** - * This whole method is a hack! To generate layout params, since no other way exists. - * Refer : http://stackoverflow.com/questions/7018267/generating-a-layoutparams-based-on-the-type-of-parent - */ + if (null == sParser) { + synchronized (ViewTypeParser.class) { if (null == sParser) { - synchronized (ViewTypeParser.class) { - if (null == sParser) { - initializeAttributeSet(parent); - } - } + initializeAttributeSet(parent); } - - return parent.generateLayoutParams(sParser); + } } - private void initializeAttributeSet(@NonNull ViewGroup parent) { - sParser = parent.getResources().getLayout(R.layout.layout_params_hack); - //noinspection StatementWithEmptyBody - try { - //noinspection StatementWithEmptyBody - while (sParser.nextToken() != XmlPullParser.START_TAG) { - // Skip everything until the view tag. - } - } catch (XmlPullParserException | IOException e) { - e.printStackTrace(); - } + return parent.generateLayoutParams(sParser); + } + + private void initializeAttributeSet(@NonNull ViewGroup parent) { + sParser = parent.getResources().getLayout(R.layout.layout_params_hack); + //noinspection StatementWithEmptyBody + try { + //noinspection StatementWithEmptyBody + while (sParser.nextToken() != XmlPullParser.START_TAG) { + // Skip everything until the view tag. + } + } catch (XmlPullParserException | IOException e) { + e.printStackTrace(); } + } - /** - * @author adityasharat - */ - public static class AttributeSet { + /** + * @author adityasharat + */ + public static class AttributeSet { - @Nullable - private final Map attributes; + @Nullable + private final Map attributes; - @Nullable - private final AttributeSet parent; + @Nullable + private final AttributeSet parent; - private final int offset; + private final int offset; - AttributeSet(@Nullable Map attributes, @Nullable AttributeSet parent, int offset) { - this.attributes = attributes; - this.parent = parent; - int parentOffset = null != parent ? parent.getOffset() : 0; - this.offset = parentOffset - offset; - } + AttributeSet(@Nullable Map attributes, @Nullable AttributeSet parent, int offset) { + this.attributes = attributes; + this.parent = parent; + int parentOffset = null != parent ? parent.getOffset() : 0; + this.offset = parentOffset - offset; + } - @Nullable - public Attribute getAttribute(String name) { - Attribute attribute = null != attributes ? attributes.get(name) : null; - if (null != attribute) { - return attribute; - } else if (null != parent) { - return parent.getAttribute(name); - } else { - return null; - } - } + @Nullable + public Attribute getAttribute(String name) { + Attribute attribute = null != attributes ? attributes.get(name) : null; + if (null != attribute) { + return attribute; + } else if (null != parent) { + return parent.getAttribute(name); + } else { + return null; + } + } - int getOffset() { - return offset; - } + int getOffset() { + return offset; + } - public static class Attribute { + public static class Attribute { - public final int id; + public final int id; - @NonNull - public final AttributeProcessor processor; + @NonNull + public final AttributeProcessor processor; - Attribute(int id, @NonNull AttributeProcessor processor) { - this.processor = processor; - this.id = id; - } - } + Attribute(int id, @NonNull AttributeProcessor processor) { + this.processor = processor; + this.id = id; + } } + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/exceptions/ProteusInflateException.java b/proteus-core/src/main/java/com/flipkart/android/proteus/exceptions/ProteusInflateException.java index 0f71b329..656f9ff0 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/exceptions/ProteusInflateException.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/exceptions/ProteusInflateException.java @@ -26,7 +26,7 @@ public class ProteusInflateException extends InflateException { - public ProteusInflateException(String message) { - super(message); - } + public ProteusInflateException(String message) { + super(message); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/managers/AdapterBasedViewManager.java b/proteus-core/src/main/java/com/flipkart/android/proteus/managers/AdapterBasedViewManager.java index 0fc0de5a..0842248e 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/managers/AdapterBasedViewManager.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/managers/AdapterBasedViewManager.java @@ -31,17 +31,17 @@ */ public class AdapterBasedViewManager extends ViewGroupManager { - public AdapterBasedViewManager(@NonNull ProteusContext context, @NonNull ViewTypeParser parser, - @NonNull View view, @NonNull Layout layout, @NonNull DataContext dataContext) { - super(context, parser, view, layout, dataContext); - } + public AdapterBasedViewManager(@NonNull ProteusContext context, @NonNull ViewTypeParser parser, + @NonNull View view, @NonNull Layout layout, @NonNull DataContext dataContext) { + super(context, parser, view, layout, dataContext); + } - /** - * Ignore updating the children in this case, that - * should be handled by the adapter attached to the view. - */ - @Override - protected void updateChildren() { + /** + * Ignore updating the children in this case, that + * should be handled by the adapter attached to the view. + */ + @Override + protected void updateChildren() { - } + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/managers/ViewGroupManager.java b/proteus-core/src/main/java/com/flipkart/android/proteus/managers/ViewGroupManager.java index 9f608c4c..498ea1ca 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/managers/ViewGroupManager.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/managers/ViewGroupManager.java @@ -36,32 +36,32 @@ public class ViewGroupManager extends ViewManager { - public boolean hasDataBoundChildren; + public boolean hasDataBoundChildren; - public ViewGroupManager(@NonNull ProteusContext context, @NonNull ViewTypeParser parser, - @NonNull View view, @NonNull Layout layout, @NonNull DataContext dataContext) { - super(context, parser, view, layout, dataContext); - hasDataBoundChildren = false; - } + public ViewGroupManager(@NonNull ProteusContext context, @NonNull ViewTypeParser parser, + @NonNull View view, @NonNull Layout layout, @NonNull DataContext dataContext) { + super(context, parser, view, layout, dataContext); + hasDataBoundChildren = false; + } - @Override - public void update(@Nullable ObjectValue data) { - super.update(data); - updateChildren(); - } + @Override + public void update(@Nullable ObjectValue data) { + super.update(data); + updateChildren(); + } - protected void updateChildren() { - if (!hasDataBoundChildren && view instanceof ViewGroup) { - ViewGroup parent = (ViewGroup) view; - int count = parent.getChildCount(); - View child; + protected void updateChildren() { + if (!hasDataBoundChildren && view instanceof ViewGroup) { + ViewGroup parent = (ViewGroup) view; + int count = parent.getChildCount(); + View child; - for (int index = 0; index < count; index++) { - child = parent.getChildAt(index); - if (child instanceof ProteusView) { - ((ProteusView) child).getViewManager().update(dataContext.getData()); - } - } + for (int index = 0; index < count; index++) { + child = parent.getChildAt(index); + if (child instanceof ProteusView) { + ((ProteusView) child).getViewManager().update(dataContext.getData()); } + } } + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/managers/ViewManager.java b/proteus-core/src/main/java/com/flipkart/android/proteus/managers/ViewManager.java index abaa8520..380e42d2 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/managers/ViewManager.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/managers/ViewManager.java @@ -38,111 +38,111 @@ */ public class ViewManager implements ProteusView.Manager { - @NonNull - protected final ProteusContext context; - - @NonNull - protected final View view; - - @NonNull - protected final Layout layout; - - @NonNull - protected final DataContext dataContext; - - @NonNull - protected final ViewTypeParser parser; - - @Nullable - protected final List boundAttributes; - - @Nullable - protected Object extras; - - public ViewManager(@NonNull ProteusContext context, @NonNull ViewTypeParser parser, - @NonNull View view, @NonNull Layout layout, @NonNull DataContext dataContext) { - this.context = context; - this.parser = parser; - this.view = view; - this.layout = layout; - this.dataContext = dataContext; - - if (null != layout.attributes) { - List boundAttributes = new ArrayList<>(); - for (Layout.Attribute attribute : layout.attributes) { - if (attribute.value.isBinding()) { - boundAttributes.add(new BoundAttribute(attribute.id, attribute.value.getAsBinding())); - } - } - if (boundAttributes.size() > 0) { - this.boundAttributes = boundAttributes; - } else { - this.boundAttributes = null; - } - } else { - this.boundAttributes = null; - } - } + @NonNull + protected final ProteusContext context; - @Override - public void update(@Nullable ObjectValue data) { - // update the data context so all child views can refer to new data - if (data != null) { - updateDataContext(data); - } + @NonNull + protected final View view; - // update the bound attributes of this view - if (this.boundAttributes != null) { - for (BoundAttribute boundAttribute : this.boundAttributes) { - this.handleBinding(boundAttribute); - } - } - } + @NonNull + protected final Layout layout; - @Nullable - @Override - public View findViewById(@NonNull String id) { - return view.findViewById(context.getInflater().getUniqueViewId(id)); - } + @NonNull + protected final DataContext dataContext; - @NonNull - @Override - public ProteusContext getContext() { - return this.context; - } + @NonNull + protected final ViewTypeParser parser; - @NonNull - @Override - public Layout getLayout() { - return this.layout; - } + @Nullable + protected final List boundAttributes; - @NonNull - public DataContext getDataContext() { - return dataContext; - } + @Nullable + protected Object extras; - @Nullable - @Override - public Object getExtras() { - return this.extras; - } + public ViewManager(@NonNull ProteusContext context, @NonNull ViewTypeParser parser, + @NonNull View view, @NonNull Layout layout, @NonNull DataContext dataContext) { + this.context = context; + this.parser = parser; + this.view = view; + this.layout = layout; + this.dataContext = dataContext; - @Override - public void setExtras(@Nullable Object extras) { - this.extras = extras; + if (null != layout.attributes) { + List boundAttributes = new ArrayList<>(); + for (Layout.Attribute attribute : layout.attributes) { + if (attribute.value.isBinding()) { + boundAttributes.add(new BoundAttribute(attribute.id, attribute.value.getAsBinding())); + } + } + if (boundAttributes.size() > 0) { + this.boundAttributes = boundAttributes; + } else { + this.boundAttributes = null; + } + } else { + this.boundAttributes = null; } + } - private void updateDataContext(ObjectValue data) { - if (dataContext.hasOwnProperties()) { - dataContext.update(context, data); - } else { - dataContext.setData(data); - } + @Override + public void update(@Nullable ObjectValue data) { + // update the data context so all child views can refer to new data + if (data != null) { + updateDataContext(data); } - private void handleBinding(BoundAttribute boundAttribute) { - //noinspection unchecked - parser.handleAttribute(view, boundAttribute.attributeId, boundAttribute.binding); + // update the bound attributes of this view + if (this.boundAttributes != null) { + for (BoundAttribute boundAttribute : this.boundAttributes) { + this.handleBinding(boundAttribute); + } + } + } + + @Nullable + @Override + public View findViewById(@NonNull String id) { + return view.findViewById(context.getInflater().getUniqueViewId(id)); + } + + @NonNull + @Override + public ProteusContext getContext() { + return this.context; + } + + @NonNull + @Override + public Layout getLayout() { + return this.layout; + } + + @NonNull + public DataContext getDataContext() { + return dataContext; + } + + @Nullable + @Override + public Object getExtras() { + return this.extras; + } + + @Override + public void setExtras(@Nullable Object extras) { + this.extras = extras; + } + + private void updateDataContext(ObjectValue data) { + if (dataContext.hasOwnProperties()) { + dataContext.update(context, data); + } else { + dataContext.setData(data); } + } + + private void handleBinding(BoundAttribute boundAttribute) { + //noinspection unchecked + parser.handleAttribute(view, boundAttribute.attributeId, boundAttribute.binding); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/IncludeParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/IncludeParser.java index e5bebcb7..c3c7cec1 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/IncludeParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/IncludeParser.java @@ -41,42 +41,42 @@ public class IncludeParser extends ViewTypeParser { - @NonNull - @Override - public String getType() { - return "include"; - } - - @Nullable - @Override - public String getParentType() { - return "View"; - } + @NonNull + @Override + public String getType() { + return "include"; + } - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout include, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { + @Nullable + @Override + public String getParentType() { + return "View"; + } - if (include.extras == null) { - throw new IllegalArgumentException("required attribute 'layout' missing."); - } + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout include, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { - Value type = include.extras.get(ProteusConstants.LAYOUT); - if (null == type || !type.isPrimitive()) { - throw new ProteusInflateException("required attribute 'layout' missing or is not a string"); - } + if (include.extras == null) { + throw new IllegalArgumentException("required attribute 'layout' missing."); + } - Layout layout = context.getLayout(type.getAsString()); - if (null == layout) { - throw new ProteusInflateException("Layout '" + type + "' not found"); - } + Value type = include.extras.get(ProteusConstants.LAYOUT); + if (null == type || !type.isPrimitive()) { + throw new ProteusInflateException("required attribute 'layout' missing or is not a string"); + } - return context.getInflater().inflate(layout.merge(include), data, parent, dataIndex); + Layout layout = context.getLayout(type.getAsString()); + if (null == layout) { + throw new ProteusInflateException("Layout '" + type + "' not found"); } - @Override - protected void addAttributeProcessors() { + return context.getInflater().inflate(layout.merge(include), data, parent, dataIndex); + } - } + @Override + protected void addAttributeProcessors() { + + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/ParseHelper.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/ParseHelper.java index 1d3dfbbb..4c014af1 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/ParseHelper.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/ParseHelper.java @@ -42,347 +42,347 @@ */ public class ParseHelper { - private static final String TAG = "ParseHelper"; - - private static final String FALSE = "false"; - - private static final String VISIBLE = "visible"; - private static final String INVISIBLE = "invisible"; - private static final String GONE = "gone"; - - private static final String CENTER = "center"; - private static final String CENTER_HORIZONTAL = "center_horizontal"; - private static final String CENTER_VERTICAL = "center_vertical"; - private static final String LEFT = "left"; - private static final String RIGHT = "right"; - private static final String TOP = "top"; - private static final String BOTTOM = "bottom"; - private static final String START = "start"; - private static final String END = "end"; - private static final String MIDDLE = "middle"; - private static final String BEGINNING = "beginning"; - private static final String MARQUEE = "marquee"; - - private static final String BOLD = "bold"; - private static final String ITALIC = "italic"; - private static final String BOLD_ITALIC = "bold|italic"; - - private static final String TEXT_ALIGNMENT_INHERIT = "inherit"; - private static final String TEXT_ALIGNMENT_GRAVITY = "gravity"; - private static final String TEXT_ALIGNMENT_CENTER = "center"; - private static final String TEXT_ALIGNMENT_TEXT_START = "start"; - private static final String TEXT_ALIGNMENT_TEXT_END = "end"; - private static final String TEXT_ALIGNMENT_VIEW_START = "viewStart"; - private static final String TEXT_ALIGNMENT_VIEW_END = "viewEnd"; - - private static final String TWEEN_LOCAL_RESOURCE_STR = "@anim/"; - - private static final Map sVisibilityMap = new HashMap<>(); - private static final Map sGravityMap = new HashMap<>(); - private static final Map sDividerMode = new HashMap<>(); - private static final Map sEllipsizeMode = new HashMap<>(); - private static final Map sVisibilityMode = new HashMap<>(); - private static final Map sTextAlignment = new HashMap<>(); - private static final Map sImageScaleType = new HashMap<>(); - - static { - - sVisibilityMap.put(View.VISIBLE, new Primitive(View.VISIBLE)); - sVisibilityMap.put(View.INVISIBLE, new Primitive(View.INVISIBLE)); - sVisibilityMap.put(View.GONE, new Primitive(View.GONE)); - - sGravityMap.put(CENTER, new Primitive(Gravity.CENTER)); - sGravityMap.put(CENTER_HORIZONTAL, new Primitive(Gravity.CENTER_HORIZONTAL)); - sGravityMap.put(CENTER_VERTICAL, new Primitive(Gravity.CENTER_VERTICAL)); - sGravityMap.put(LEFT, new Primitive(Gravity.LEFT)); - sGravityMap.put(RIGHT, new Primitive(Gravity.RIGHT)); - sGravityMap.put(TOP, new Primitive(Gravity.TOP)); - sGravityMap.put(BOTTOM, new Primitive(Gravity.BOTTOM)); - sGravityMap.put(START, new Primitive(Gravity.START)); - sGravityMap.put(END, new Primitive(Gravity.END)); - - sDividerMode.put(END, LinearLayout.SHOW_DIVIDER_END); - sDividerMode.put(MIDDLE, LinearLayout.SHOW_DIVIDER_MIDDLE); - sDividerMode.put(BEGINNING, LinearLayout.SHOW_DIVIDER_BEGINNING); - - sEllipsizeMode.put(END, TextUtils.TruncateAt.END); - sEllipsizeMode.put(START, TextUtils.TruncateAt.START); - sEllipsizeMode.put(MARQUEE, TextUtils.TruncateAt.MARQUEE); - sEllipsizeMode.put(MIDDLE, TextUtils.TruncateAt.MIDDLE); - - sVisibilityMode.put(VISIBLE, View.VISIBLE); - sVisibilityMode.put(INVISIBLE, View.INVISIBLE); - sVisibilityMode.put(GONE, View.GONE); - - sImageScaleType.put(CENTER, ImageView.ScaleType.CENTER); - sImageScaleType.put("center_crop", ImageView.ScaleType.CENTER_CROP); - sImageScaleType.put("center_inside", ImageView.ScaleType.CENTER_INSIDE); - sImageScaleType.put("fitCenter", ImageView.ScaleType.FIT_CENTER); - sImageScaleType.put("fit_xy", ImageView.ScaleType.FIT_XY); - sImageScaleType.put("matrix", ImageView.ScaleType.MATRIX); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - sTextAlignment.put(TEXT_ALIGNMENT_INHERIT, View.TEXT_ALIGNMENT_INHERIT); - } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - sTextAlignment.put(TEXT_ALIGNMENT_GRAVITY, View.TEXT_ALIGNMENT_GRAVITY); - sTextAlignment.put(TEXT_ALIGNMENT_CENTER, View.TEXT_ALIGNMENT_CENTER); - sTextAlignment.put(TEXT_ALIGNMENT_TEXT_START, View.TEXT_ALIGNMENT_TEXT_START); - sTextAlignment.put(TEXT_ALIGNMENT_TEXT_END, View.TEXT_ALIGNMENT_TEXT_END); - sTextAlignment.put(TEXT_ALIGNMENT_VIEW_START, View.TEXT_ALIGNMENT_VIEW_START); - sTextAlignment.put(TEXT_ALIGNMENT_VIEW_END, View.TEXT_ALIGNMENT_VIEW_END); - } + private static final String TAG = "ParseHelper"; + + private static final String FALSE = "false"; + + private static final String VISIBLE = "visible"; + private static final String INVISIBLE = "invisible"; + private static final String GONE = "gone"; + + private static final String CENTER = "center"; + private static final String CENTER_HORIZONTAL = "center_horizontal"; + private static final String CENTER_VERTICAL = "center_vertical"; + private static final String LEFT = "left"; + private static final String RIGHT = "right"; + private static final String TOP = "top"; + private static final String BOTTOM = "bottom"; + private static final String START = "start"; + private static final String END = "end"; + private static final String MIDDLE = "middle"; + private static final String BEGINNING = "beginning"; + private static final String MARQUEE = "marquee"; + + private static final String BOLD = "bold"; + private static final String ITALIC = "italic"; + private static final String BOLD_ITALIC = "bold|italic"; + + private static final String TEXT_ALIGNMENT_INHERIT = "inherit"; + private static final String TEXT_ALIGNMENT_GRAVITY = "gravity"; + private static final String TEXT_ALIGNMENT_CENTER = "center"; + private static final String TEXT_ALIGNMENT_TEXT_START = "start"; + private static final String TEXT_ALIGNMENT_TEXT_END = "end"; + private static final String TEXT_ALIGNMENT_VIEW_START = "viewStart"; + private static final String TEXT_ALIGNMENT_VIEW_END = "viewEnd"; + + private static final String TWEEN_LOCAL_RESOURCE_STR = "@anim/"; + + private static final Map sVisibilityMap = new HashMap<>(); + private static final Map sGravityMap = new HashMap<>(); + private static final Map sDividerMode = new HashMap<>(); + private static final Map sEllipsizeMode = new HashMap<>(); + private static final Map sVisibilityMode = new HashMap<>(); + private static final Map sTextAlignment = new HashMap<>(); + private static final Map sImageScaleType = new HashMap<>(); + + static { + + sVisibilityMap.put(View.VISIBLE, new Primitive(View.VISIBLE)); + sVisibilityMap.put(View.INVISIBLE, new Primitive(View.INVISIBLE)); + sVisibilityMap.put(View.GONE, new Primitive(View.GONE)); + + sGravityMap.put(CENTER, new Primitive(Gravity.CENTER)); + sGravityMap.put(CENTER_HORIZONTAL, new Primitive(Gravity.CENTER_HORIZONTAL)); + sGravityMap.put(CENTER_VERTICAL, new Primitive(Gravity.CENTER_VERTICAL)); + sGravityMap.put(LEFT, new Primitive(Gravity.LEFT)); + sGravityMap.put(RIGHT, new Primitive(Gravity.RIGHT)); + sGravityMap.put(TOP, new Primitive(Gravity.TOP)); + sGravityMap.put(BOTTOM, new Primitive(Gravity.BOTTOM)); + sGravityMap.put(START, new Primitive(Gravity.START)); + sGravityMap.put(END, new Primitive(Gravity.END)); + + sDividerMode.put(END, LinearLayout.SHOW_DIVIDER_END); + sDividerMode.put(MIDDLE, LinearLayout.SHOW_DIVIDER_MIDDLE); + sDividerMode.put(BEGINNING, LinearLayout.SHOW_DIVIDER_BEGINNING); + + sEllipsizeMode.put(END, TextUtils.TruncateAt.END); + sEllipsizeMode.put(START, TextUtils.TruncateAt.START); + sEllipsizeMode.put(MARQUEE, TextUtils.TruncateAt.MARQUEE); + sEllipsizeMode.put(MIDDLE, TextUtils.TruncateAt.MIDDLE); + + sVisibilityMode.put(VISIBLE, View.VISIBLE); + sVisibilityMode.put(INVISIBLE, View.INVISIBLE); + sVisibilityMode.put(GONE, View.GONE); + + sImageScaleType.put(CENTER, ImageView.ScaleType.CENTER); + sImageScaleType.put("center_crop", ImageView.ScaleType.CENTER_CROP); + sImageScaleType.put("center_inside", ImageView.ScaleType.CENTER_INSIDE); + sImageScaleType.put("fitCenter", ImageView.ScaleType.FIT_CENTER); + sImageScaleType.put("fit_xy", ImageView.ScaleType.FIT_XY); + sImageScaleType.put("matrix", ImageView.ScaleType.MATRIX); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + sTextAlignment.put(TEXT_ALIGNMENT_INHERIT, View.TEXT_ALIGNMENT_INHERIT); } - - public static int parseInt(String attributeValue) { - int number; - if (ProteusConstants.DATA_NULL.equals(attributeValue)) { - return 0; - } - try { - number = Integer.parseInt(attributeValue); - } catch (NumberFormatException e) { - if (ProteusConstants.isLoggingEnabled()) { - Log.e(TAG, attributeValue + " is NAN. Error: " + e.getMessage()); - } - number = 0; - } - return number; - } - - public static IntResult parseIntUnsafe(String s) { - if (s == null) { - return new IntResult("null string"); - } - - int num; - final int len = s.length(); - final char ch = s.charAt(0); - int d = ch - '0'; - if (d < 0 || d > 9) { - return new IntResult("Malformed: " + s); - } - num = d; - - int i = 1; - while (i < len) { - d = s.charAt(i++) - '0'; - if (d < 0 || d > 9) { - return new IntResult("Malformed: " + s); - } - num *= 10; - num += d; - } - - return new IntResult(null, num); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + sTextAlignment.put(TEXT_ALIGNMENT_GRAVITY, View.TEXT_ALIGNMENT_GRAVITY); + sTextAlignment.put(TEXT_ALIGNMENT_CENTER, View.TEXT_ALIGNMENT_CENTER); + sTextAlignment.put(TEXT_ALIGNMENT_TEXT_START, View.TEXT_ALIGNMENT_TEXT_START); + sTextAlignment.put(TEXT_ALIGNMENT_TEXT_END, View.TEXT_ALIGNMENT_TEXT_END); + sTextAlignment.put(TEXT_ALIGNMENT_VIEW_START, View.TEXT_ALIGNMENT_VIEW_START); + sTextAlignment.put(TEXT_ALIGNMENT_VIEW_END, View.TEXT_ALIGNMENT_VIEW_END); } + } - public static float parseFloat(String value) { - float number = 0; - if (null != value && value.length() > 0) { - try { - number = Float.parseFloat(value); - } catch (NumberFormatException e) { - number = 0; - } - } - return number; + public static int parseInt(String attributeValue) { + int number; + if (ProteusConstants.DATA_NULL.equals(attributeValue)) { + return 0; } - - public static double parseDouble(String attributeValue) { - double number; - if (ProteusConstants.DATA_NULL.equals(attributeValue)) { - return 0; - } - try { - number = Double.parseDouble(attributeValue); - } catch (NumberFormatException e) { - if (ProteusConstants.isLoggingEnabled()) { - Log.e(TAG, attributeValue + " is NAN. Error: " + e.getMessage()); - } - number = 0; - } - return number; - } - - public static int parseGravity(String value) { - String[] gravities = value.split("\\|"); - int returnGravity = Gravity.NO_GRAVITY; - for (String gravity : gravities) { - Primitive gravityValue = sGravityMap.get(gravity); - if (null != gravityValue) { - returnGravity |= gravityValue.getAsInt(); - } - } - return returnGravity; + try { + number = Integer.parseInt(attributeValue); + } catch (NumberFormatException e) { + if (ProteusConstants.isLoggingEnabled()) { + Log.e(TAG, attributeValue + " is NAN. Error: " + e.getMessage()); + } + number = 0; } + return number; + } - public static Primitive getGravity(String value) { - return new Primitive(parseGravity(value)); + public static IntResult parseIntUnsafe(String s) { + if (s == null) { + return new IntResult("null string"); } - public static int parseDividerMode(String attributeValue) { - Integer returnValue = sDividerMode.get(attributeValue); - return returnValue == null ? LinearLayout.SHOW_DIVIDER_NONE : returnValue; + int num; + final int len = s.length(); + final char ch = s.charAt(0); + int d = ch - '0'; + if (d < 0 || d > 9) { + return new IntResult("Malformed: " + s); } - - public static Enum parseEllipsize(String attributeValue) { - Enum returnValue = sEllipsizeMode.get(attributeValue); - return returnValue == null ? TextUtils.TruncateAt.END : returnValue; - } - - public static int parseVisibility(@Nullable Value value) { - Integer returnValue = null; - if (null != value && value.isPrimitive()) { - String attributeValue = value.getAsString(); - returnValue = sVisibilityMode.get(attributeValue); - if (null == returnValue && - (attributeValue.isEmpty() || FALSE.equals(attributeValue) || ProteusConstants.DATA_NULL.equals(attributeValue))) { - returnValue = View.GONE; - } - } else //noinspection ConstantConditions - if (value.isNull()) { - returnValue = View.GONE; - } - return returnValue == null ? View.VISIBLE : returnValue; - } - - public static Primitive getVisibility(int visibility) { - Primitive value = sVisibilityMap.get(visibility); - return null != value ? value : sVisibilityMap.get(View.GONE); + num = d; + + int i = 1; + while (i < len) { + d = s.charAt(i++) - '0'; + if (d < 0 || d > 9) { + return new IntResult("Malformed: " + s); + } + num *= 10; + num += d; } - public static int parseColor(String color) { - try { - return Color.parseColor(color); - } catch (IllegalArgumentException ex) { - if (ProteusConstants.isLoggingEnabled()) { - Log.e(TAG, "Invalid color : " + color + ". Using #000000"); - } - return Color.BLACK; - } + return new IntResult(null, num); + } + + public static float parseFloat(String value) { + float number = 0; + if (null != value && value.length() > 0) { + try { + number = Float.parseFloat(value); + } catch (NumberFormatException e) { + number = 0; + } } + return number; + } - public static boolean parseBoolean(@Nullable Value value) { - // TODO: we should consider 0 as false too. - return null != value && value.isPrimitive() && value.getAsPrimitive().isBoolean() ? value.getAsBoolean() : null != value && !value.isNull(); + public static double parseDouble(String attributeValue) { + double number; + if (ProteusConstants.DATA_NULL.equals(attributeValue)) { + return 0; } - - public static int parseRelativeLayoutBoolean(boolean value) { - return value ? RelativeLayout.TRUE : 0; + try { + number = Double.parseDouble(attributeValue); + } catch (NumberFormatException e) { + if (ProteusConstants.isLoggingEnabled()) { + Log.e(TAG, attributeValue + " is NAN. Error: " + e.getMessage()); + } + number = 0; } - - public static void addRelativeLayoutRule(View view, int verb, int anchor) { - ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); - if (layoutParams instanceof RelativeLayout.LayoutParams) { - RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) layoutParams; - params.addRule(verb, anchor); - view.setLayoutParams(params); - } else { - if (ProteusConstants.isLoggingEnabled()) { - Log.e(TAG, "cannot add relative layout rules when container is not relative"); - } - } + return number; + } + + public static int parseGravity(String value) { + String[] gravities = value.split("\\|"); + int returnGravity = Gravity.NO_GRAVITY; + for (String gravity : gravities) { + Primitive gravityValue = sGravityMap.get(gravity); + if (null != gravityValue) { + returnGravity |= gravityValue.getAsInt(); + } } - - public static int parseTextStyle(String attributeValue) { - int typeface = Typeface.NORMAL; - if (attributeValue != null) { - attributeValue = attributeValue.toLowerCase(); - switch (attributeValue) { - case BOLD: - typeface = Typeface.BOLD; - break; - case ITALIC: - typeface = Typeface.ITALIC; - break; - case BOLD_ITALIC: - typeface = Typeface.BOLD_ITALIC; - break; - default: - typeface = Typeface.NORMAL; - break; - } - } - return typeface; + return returnGravity; + } + + public static Primitive getGravity(String value) { + return new Primitive(parseGravity(value)); + } + + public static int parseDividerMode(String attributeValue) { + Integer returnValue = sDividerMode.get(attributeValue); + return returnValue == null ? LinearLayout.SHOW_DIVIDER_NONE : returnValue; + } + + public static Enum parseEllipsize(String attributeValue) { + Enum returnValue = sEllipsizeMode.get(attributeValue); + return returnValue == null ? TextUtils.TruncateAt.END : returnValue; + } + + public static int parseVisibility(@Nullable Value value) { + Integer returnValue = null; + if (null != value && value.isPrimitive()) { + String attributeValue = value.getAsString(); + returnValue = sVisibilityMode.get(attributeValue); + if (null == returnValue && + (attributeValue.isEmpty() || FALSE.equals(attributeValue) || ProteusConstants.DATA_NULL.equals(attributeValue))) { + returnValue = View.GONE; + } + } else //noinspection ConstantConditions + if (value.isNull()) { + returnValue = View.GONE; + } + return returnValue == null ? View.VISIBLE : returnValue; + } + + public static Primitive getVisibility(int visibility) { + Primitive value = sVisibilityMap.get(visibility); + return null != value ? value : sVisibilityMap.get(View.GONE); + } + + public static int parseColor(String color) { + try { + return Color.parseColor(color); + } catch (IllegalArgumentException ex) { + if (ProteusConstants.isLoggingEnabled()) { + Log.e(TAG, "Invalid color : " + color + ". Using #000000"); + } + return Color.BLACK; } - - public static boolean isTweenAnimationResource(String attributeValue) { - return attributeValue.startsWith(TWEEN_LOCAL_RESOURCE_STR); + } + + public static boolean parseBoolean(@Nullable Value value) { + // TODO: we should consider 0 as false too. + return null != value && value.isPrimitive() && value.getAsPrimitive().isBoolean() ? value.getAsBoolean() : null != value && !value.isNull(); + } + + public static int parseRelativeLayoutBoolean(boolean value) { + return value ? RelativeLayout.TRUE : 0; + } + + public static void addRelativeLayoutRule(View view, int verb, int anchor) { + ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); + if (layoutParams instanceof RelativeLayout.LayoutParams) { + RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) layoutParams; + params.addRule(verb, anchor); + view.setLayoutParams(params); + } else { + if (ProteusConstants.isLoggingEnabled()) { + Log.e(TAG, "cannot add relative layout rules when container is not relative"); + } } - - /** - * Uses reflection to fetch the R.id from the given class. - * This method is faster than using {@link android.content.res.Resources#getResourceName(int)} - * - * @param variableName the name of the variable - * @param с The class - * @return resource id - */ - public static int getResId(String variableName, Class с) { - Field field; - int resId = 0; - try { - field = с.getField(variableName); - resId = field.getInt(null); - } catch (Exception e) { - e.printStackTrace(); - } - return resId; - + } + + public static int parseTextStyle(String attributeValue) { + int typeface = Typeface.NORMAL; + if (attributeValue != null) { + attributeValue = attributeValue.toLowerCase(); + switch (attributeValue) { + case BOLD: + typeface = Typeface.BOLD; + break; + case ITALIC: + typeface = Typeface.ITALIC; + break; + case BOLD_ITALIC: + typeface = Typeface.BOLD_ITALIC; + break; + default: + typeface = Typeface.NORMAL; + break; + } } - - /** - * Get int resource id, by just passing the string value of android:id from xml file. - * Note : This method only works for @android:id or @+android:id right now - * - * @param fullResIdString the string id of the view - * @return the number id of the view - */ - public static int getAndroidXmlResId(String fullResIdString) { - if (fullResIdString != null) { - int i = fullResIdString.indexOf("/"); - if (i >= 0) { - String idString = fullResIdString.substring(i + 1); - return getResId(idString, android.R.id.class); - } - } - return View.NO_ID; + return typeface; + } + + public static boolean isTweenAnimationResource(String attributeValue) { + return attributeValue.startsWith(TWEEN_LOCAL_RESOURCE_STR); + } + + /** + * Uses reflection to fetch the R.id from the given class. + * This method is faster than using {@link android.content.res.Resources#getResourceName(int)} + * + * @param variableName the name of the variable + * @param с The class + * @return resource id + */ + public static int getResId(String variableName, Class с) { + Field field; + int resId = 0; + try { + field = с.getField(variableName); + resId = field.getInt(null); + } catch (Exception e) { + e.printStackTrace(); } - - /** - * Parses a image view scale type - * - * @param attributeValue value of the scale type attribute - * @return {@link android.widget.ImageView.ScaleType} enum - */ - public static ImageView.ScaleType parseScaleType(String attributeValue) { - return !TextUtils.isEmpty(attributeValue) ? sImageScaleType.get(attributeValue) : null; + return resId; + + } + + /** + * Get int resource id, by just passing the string value of android:id from xml file. + * Note : This method only works for @android:id or @+android:id right now + * + * @param fullResIdString the string id of the view + * @return the number id of the view + */ + public static int getAndroidXmlResId(String fullResIdString) { + if (fullResIdString != null) { + int i = fullResIdString.indexOf("/"); + if (i >= 0) { + String idString = fullResIdString.substring(i + 1); + return getResId(idString, android.R.id.class); + } } - - /** - * parses Text Alignment - * - * @param attributeValue value of the typeface attribute - * @return the text alignment value - */ - public static Integer parseTextAlignment(String attributeValue) { - return !TextUtils.isEmpty(attributeValue) ? sTextAlignment.get(attributeValue) : null; + return View.NO_ID; + } + + /** + * Parses a image view scale type + * + * @param attributeValue value of the scale type attribute + * @return {@link android.widget.ImageView.ScaleType} enum + */ + public static ImageView.ScaleType parseScaleType(String attributeValue) { + return !TextUtils.isEmpty(attributeValue) ? sImageScaleType.get(attributeValue) : null; + } + + /** + * parses Text Alignment + * + * @param attributeValue value of the typeface attribute + * @return the text alignment value + */ + public static Integer parseTextAlignment(String attributeValue) { + return !TextUtils.isEmpty(attributeValue) ? sTextAlignment.get(attributeValue) : null; + } + + public static class IntResult { + @Nullable + public final String error; + public final int result; + + public IntResult(@Nullable String error, int result) { + this.error = error; + this.result = result; } - public static class IntResult { - @Nullable - public final String error; - public final int result; - - public IntResult(@Nullable String error, int result) { - this.error = error; - this.result = result; - } - - public IntResult(@Nullable String error) { - this.error = error; - this.result = -1; - } + public IntResult(@Nullable String error) { + this.error = error; + this.result = -1; } + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/ViewParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/ViewParser.java index eba5d43b..1fbd205d 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/ViewParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/ViewParser.java @@ -62,565 +62,565 @@ */ public class ViewParser extends ViewTypeParser { - private static final String TAG = "ViewParser"; - - private static final String ID_STRING_START_PATTERN = "@+id/"; - private static final String ID_STRING_START_PATTERN1 = "@id/"; - private static final String ID_STRING_NORMALIZED_PATTERN = ":id/"; - - @NonNull - @Override - public String getType() { - return "View"; - } - - @Nullable - @Override - public String getParentType() { - return null; - } - - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, - @Nullable ViewGroup parent, int dataIndex) { - return new ProteusAndroidView(context); - } - - @Override - protected void addAttributeProcessors() { - - addAttributeProcessor(Attributes.View.Activated, new BooleanAttributeProcessor() { - @Override - public void setBoolean(V view, boolean value) { - view.setActivated(value); - } - }); - - addAttributeProcessor(Attributes.View.OnClick, new EventProcessor() { - @Override - public void setOnEventListener(final V view, final Value value) { - view.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - trigger(Attributes.View.OnClick, value, (ProteusView) view); - } - }); - } - }); - - addAttributeProcessor(Attributes.View.OnLongClick, new EventProcessor() { - @Override - public void setOnEventListener(final V view, final Value value) { - view.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - trigger(Attributes.View.OnLongClick, value, (ProteusView) view); - return true; - } - }); - } - }); - - addAttributeProcessor(Attributes.View.OnTouch, new EventProcessor() { - @Override - public void setOnEventListener(final V view, final Value value) { - view.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - trigger(Attributes.View.OnTouch, value, (ProteusView) view); - return true; - } - }); - } - }); - - addAttributeProcessor(Attributes.View.Background, new DrawableResourceProcessor() { - @Override - public void setDrawable(V view, Drawable drawable) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { - //noinspection deprecation - view.setBackgroundDrawable(drawable); - } else { - view.setBackground(drawable); - } - } - }); - - addAttributeProcessor(Attributes.View.Height, new DimensionAttributeProcessor() { - @Override - public void setDimension(V view, float dimension) { - ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); - if (layoutParams != null) { - layoutParams.height = (int) dimension; - view.setLayoutParams(layoutParams); - } - } - }); - - addAttributeProcessor(Attributes.View.Width, new DimensionAttributeProcessor() { - @Override - public void setDimension(V view, float dimension) { - ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); - if (layoutParams != null) { - layoutParams.width = (int) dimension; - view.setLayoutParams(layoutParams); - } - } - }); - addAttributeProcessor(Attributes.View.Weight, new StringAttributeProcessor() { - @Override - public void setString(V view, String value) { - LinearLayout.LayoutParams layoutParams; - if (view.getLayoutParams() instanceof LinearLayout.LayoutParams) { - layoutParams = (LinearLayout.LayoutParams) view.getLayoutParams(); - layoutParams.weight = ParseHelper.parseFloat(value); - view.setLayoutParams(layoutParams); - } else { - if (ProteusConstants.isLoggingEnabled()) { - Log.e(TAG, "'weight' is only supported for LinearLayouts"); - } - } - } - }); - - addAttributeProcessor(Attributes.View.LayoutGravity, new GravityAttributeProcessor() { - @Override - public void setGravity(V view, @Gravity int gravity) { - ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); - - if (layoutParams instanceof LinearLayout.LayoutParams) { - LinearLayout.LayoutParams linearLayoutParams = (LinearLayout.LayoutParams) layoutParams; - linearLayoutParams.gravity = gravity; - view.setLayoutParams(layoutParams); - } else if (layoutParams instanceof FrameLayout.LayoutParams) { - FrameLayout.LayoutParams linearLayoutParams = (FrameLayout.LayoutParams) layoutParams; - linearLayoutParams.gravity = gravity; - view.setLayoutParams(layoutParams); - } else { - if (ProteusConstants.isLoggingEnabled()) { - Log.e(TAG, "'layout_gravity' is only supported for LinearLayout and FrameLayout"); - } - } - } - }); - - addAttributeProcessor(Attributes.View.Padding, new DimensionAttributeProcessor() { - @Override - public void setDimension(V view, float dimension) { - view.setPadding((int) dimension, (int) dimension, (int) dimension, (int) dimension); - } - }); - - addAttributeProcessor(Attributes.View.PaddingLeft, new DimensionAttributeProcessor() { - @Override - public void setDimension(V view, float dimension) { - view.setPadding((int) dimension, view.getPaddingTop(), view.getPaddingRight(), view.getPaddingBottom()); - } - }); - - addAttributeProcessor(Attributes.View.PaddingTop, new DimensionAttributeProcessor() { - @Override - public void setDimension(V view, float dimension) { - view.setPadding(view.getPaddingLeft(), (int) dimension, view.getPaddingRight(), view.getPaddingBottom()); - } - }); - - addAttributeProcessor(Attributes.View.PaddingRight, new DimensionAttributeProcessor() { - @Override - public void setDimension(V view, float dimension) { - view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), (int) dimension, view.getPaddingBottom()); - } - }); - - addAttributeProcessor(Attributes.View.PaddingBottom, new DimensionAttributeProcessor() { - @Override - public void setDimension(V view, float dimension) { - view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), view.getPaddingRight(), (int) dimension); - } - }); - - addAttributeProcessor(Attributes.View.Margin, new DimensionAttributeProcessor() { - @Override - public void setDimension(V view, float dimension) { - if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) { - ViewGroup.MarginLayoutParams layoutParams; - layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); - layoutParams.setMargins((int) dimension, (int) dimension, (int) dimension, (int) dimension); - view.setLayoutParams(layoutParams); - } else { - if (ProteusConstants.isLoggingEnabled()) { - Log.e(TAG, "margins can only be applied to views with parent ViewGroup"); - } - } - } - }); - - addAttributeProcessor(Attributes.View.MarginLeft, new DimensionAttributeProcessor() { - @Override - public void setDimension(V view, float dimension) { - if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) { - ViewGroup.MarginLayoutParams layoutParams; - layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); - layoutParams.setMargins((int) dimension, layoutParams.topMargin, layoutParams.rightMargin, layoutParams.bottomMargin); - view.setLayoutParams(layoutParams); - } else { - if (ProteusConstants.isLoggingEnabled()) { - Log.e(TAG, "margins can only be applied to views with parent ViewGroup"); - } - } - } - }); - - addAttributeProcessor(Attributes.View.MarginTop, new DimensionAttributeProcessor() { - @Override - public void setDimension(V view, float dimension) { - if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) { - ViewGroup.MarginLayoutParams layoutParams; - layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); - layoutParams.setMargins(layoutParams.leftMargin, (int) dimension, layoutParams.rightMargin, layoutParams.bottomMargin); - view.setLayoutParams(layoutParams); - } else { - if (ProteusConstants.isLoggingEnabled()) { - Log.e(TAG, "margins can only be applied to views with parent ViewGroup"); - } - } - } - }); - - addAttributeProcessor(Attributes.View.MarginRight, new DimensionAttributeProcessor() { - @Override - public void setDimension(V view, float dimension) { - if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) { - ViewGroup.MarginLayoutParams layoutParams; - layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); - layoutParams.setMargins(layoutParams.leftMargin, layoutParams.topMargin, (int) dimension, layoutParams.bottomMargin); - view.setLayoutParams(layoutParams); - } else { - if (ProteusConstants.isLoggingEnabled()) { - Log.e(TAG, "margins can only be applied to views with parent ViewGroup"); - } - } - } - }); - - addAttributeProcessor(Attributes.View.MarginBottom, new DimensionAttributeProcessor() { - @Override - public void setDimension(V view, float dimension) { - if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) { - ViewGroup.MarginLayoutParams layoutParams; - layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); - layoutParams.setMargins(layoutParams.leftMargin, layoutParams.topMargin, layoutParams.rightMargin, (int) dimension); - view.setLayoutParams(layoutParams); - } else { - if (ProteusConstants.isLoggingEnabled()) { - Log.e(TAG, "margins can only be applied to views with parent ViewGroup"); - } - } - } - }); - - addAttributeProcessor(Attributes.View.MinHeight, new DimensionAttributeProcessor() { - @Override - public void setDimension(V view, float dimension) { - view.setMinimumHeight((int) dimension); - } - }); - - addAttributeProcessor(Attributes.View.MinWidth, new DimensionAttributeProcessor() { - @Override - public void setDimension(V view, float dimension) { - view.setMinimumWidth((int) dimension); - } - }); - - addAttributeProcessor(Attributes.View.Elevation, new DimensionAttributeProcessor() { - @Override - public void setDimension(V view, float dimension) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - view.setElevation(dimension); - } - } - }); - - addAttributeProcessor(Attributes.View.Alpha, new StringAttributeProcessor() { - @Override - public void setString(V view, String value) { - view.setAlpha(ParseHelper.parseFloat(value)); - } - }); + private static final String TAG = "ViewParser"; + + private static final String ID_STRING_START_PATTERN = "@+id/"; + private static final String ID_STRING_START_PATTERN1 = "@id/"; + private static final String ID_STRING_NORMALIZED_PATTERN = ":id/"; + + @NonNull + @Override + public String getType() { + return "View"; + } + + @Nullable + @Override + public String getParentType() { + return null; + } + + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, + @Nullable ViewGroup parent, int dataIndex) { + return new ProteusAndroidView(context); + } + + @Override + protected void addAttributeProcessors() { + + addAttributeProcessor(Attributes.View.Activated, new BooleanAttributeProcessor() { + @Override + public void setBoolean(V view, boolean value) { + view.setActivated(value); + } + }); + + addAttributeProcessor(Attributes.View.OnClick, new EventProcessor() { + @Override + public void setOnEventListener(final V view, final Value value) { + view.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + trigger(Attributes.View.OnClick, value, (ProteusView) view); + } + }); + } + }); + + addAttributeProcessor(Attributes.View.OnLongClick, new EventProcessor() { + @Override + public void setOnEventListener(final V view, final Value value) { + view.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + trigger(Attributes.View.OnLongClick, value, (ProteusView) view); + return true; + } + }); + } + }); + + addAttributeProcessor(Attributes.View.OnTouch, new EventProcessor() { + @Override + public void setOnEventListener(final V view, final Value value) { + view.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + trigger(Attributes.View.OnTouch, value, (ProteusView) view); + return true; + } + }); + } + }); + + addAttributeProcessor(Attributes.View.Background, new DrawableResourceProcessor() { + @Override + public void setDrawable(V view, Drawable drawable) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { + //noinspection deprecation + view.setBackgroundDrawable(drawable); + } else { + view.setBackground(drawable); + } + } + }); + + addAttributeProcessor(Attributes.View.Height, new DimensionAttributeProcessor() { + @Override + public void setDimension(V view, float dimension) { + ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); + if (layoutParams != null) { + layoutParams.height = (int) dimension; + view.setLayoutParams(layoutParams); + } + } + }); + + addAttributeProcessor(Attributes.View.Width, new DimensionAttributeProcessor() { + @Override + public void setDimension(V view, float dimension) { + ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); + if (layoutParams != null) { + layoutParams.width = (int) dimension; + view.setLayoutParams(layoutParams); + } + } + }); + addAttributeProcessor(Attributes.View.Weight, new StringAttributeProcessor() { + @Override + public void setString(V view, String value) { + LinearLayout.LayoutParams layoutParams; + if (view.getLayoutParams() instanceof LinearLayout.LayoutParams) { + layoutParams = (LinearLayout.LayoutParams) view.getLayoutParams(); + layoutParams.weight = ParseHelper.parseFloat(value); + view.setLayoutParams(layoutParams); + } else { + if (ProteusConstants.isLoggingEnabled()) { + Log.e(TAG, "'weight' is only supported for LinearLayouts"); + } + } + } + }); + + addAttributeProcessor(Attributes.View.LayoutGravity, new GravityAttributeProcessor() { + @Override + public void setGravity(V view, @Gravity int gravity) { + ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); + + if (layoutParams instanceof LinearLayout.LayoutParams) { + LinearLayout.LayoutParams linearLayoutParams = (LinearLayout.LayoutParams) layoutParams; + linearLayoutParams.gravity = gravity; + view.setLayoutParams(layoutParams); + } else if (layoutParams instanceof FrameLayout.LayoutParams) { + FrameLayout.LayoutParams linearLayoutParams = (FrameLayout.LayoutParams) layoutParams; + linearLayoutParams.gravity = gravity; + view.setLayoutParams(layoutParams); + } else { + if (ProteusConstants.isLoggingEnabled()) { + Log.e(TAG, "'layout_gravity' is only supported for LinearLayout and FrameLayout"); + } + } + } + }); + + addAttributeProcessor(Attributes.View.Padding, new DimensionAttributeProcessor() { + @Override + public void setDimension(V view, float dimension) { + view.setPadding((int) dimension, (int) dimension, (int) dimension, (int) dimension); + } + }); + + addAttributeProcessor(Attributes.View.PaddingLeft, new DimensionAttributeProcessor() { + @Override + public void setDimension(V view, float dimension) { + view.setPadding((int) dimension, view.getPaddingTop(), view.getPaddingRight(), view.getPaddingBottom()); + } + }); + + addAttributeProcessor(Attributes.View.PaddingTop, new DimensionAttributeProcessor() { + @Override + public void setDimension(V view, float dimension) { + view.setPadding(view.getPaddingLeft(), (int) dimension, view.getPaddingRight(), view.getPaddingBottom()); + } + }); + + addAttributeProcessor(Attributes.View.PaddingRight, new DimensionAttributeProcessor() { + @Override + public void setDimension(V view, float dimension) { + view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), (int) dimension, view.getPaddingBottom()); + } + }); + + addAttributeProcessor(Attributes.View.PaddingBottom, new DimensionAttributeProcessor() { + @Override + public void setDimension(V view, float dimension) { + view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), view.getPaddingRight(), (int) dimension); + } + }); + + addAttributeProcessor(Attributes.View.Margin, new DimensionAttributeProcessor() { + @Override + public void setDimension(V view, float dimension) { + if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) { + ViewGroup.MarginLayoutParams layoutParams; + layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); + layoutParams.setMargins((int) dimension, (int) dimension, (int) dimension, (int) dimension); + view.setLayoutParams(layoutParams); + } else { + if (ProteusConstants.isLoggingEnabled()) { + Log.e(TAG, "margins can only be applied to views with parent ViewGroup"); + } + } + } + }); + + addAttributeProcessor(Attributes.View.MarginLeft, new DimensionAttributeProcessor() { + @Override + public void setDimension(V view, float dimension) { + if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) { + ViewGroup.MarginLayoutParams layoutParams; + layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); + layoutParams.setMargins((int) dimension, layoutParams.topMargin, layoutParams.rightMargin, layoutParams.bottomMargin); + view.setLayoutParams(layoutParams); + } else { + if (ProteusConstants.isLoggingEnabled()) { + Log.e(TAG, "margins can only be applied to views with parent ViewGroup"); + } + } + } + }); + + addAttributeProcessor(Attributes.View.MarginTop, new DimensionAttributeProcessor() { + @Override + public void setDimension(V view, float dimension) { + if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) { + ViewGroup.MarginLayoutParams layoutParams; + layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); + layoutParams.setMargins(layoutParams.leftMargin, (int) dimension, layoutParams.rightMargin, layoutParams.bottomMargin); + view.setLayoutParams(layoutParams); + } else { + if (ProteusConstants.isLoggingEnabled()) { + Log.e(TAG, "margins can only be applied to views with parent ViewGroup"); + } + } + } + }); + + addAttributeProcessor(Attributes.View.MarginRight, new DimensionAttributeProcessor() { + @Override + public void setDimension(V view, float dimension) { + if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) { + ViewGroup.MarginLayoutParams layoutParams; + layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); + layoutParams.setMargins(layoutParams.leftMargin, layoutParams.topMargin, (int) dimension, layoutParams.bottomMargin); + view.setLayoutParams(layoutParams); + } else { + if (ProteusConstants.isLoggingEnabled()) { + Log.e(TAG, "margins can only be applied to views with parent ViewGroup"); + } + } + } + }); + + addAttributeProcessor(Attributes.View.MarginBottom, new DimensionAttributeProcessor() { + @Override + public void setDimension(V view, float dimension) { + if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) { + ViewGroup.MarginLayoutParams layoutParams; + layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); + layoutParams.setMargins(layoutParams.leftMargin, layoutParams.topMargin, layoutParams.rightMargin, (int) dimension); + view.setLayoutParams(layoutParams); + } else { + if (ProteusConstants.isLoggingEnabled()) { + Log.e(TAG, "margins can only be applied to views with parent ViewGroup"); + } + } + } + }); + + addAttributeProcessor(Attributes.View.MinHeight, new DimensionAttributeProcessor() { + @Override + public void setDimension(V view, float dimension) { + view.setMinimumHeight((int) dimension); + } + }); + + addAttributeProcessor(Attributes.View.MinWidth, new DimensionAttributeProcessor() { + @Override + public void setDimension(V view, float dimension) { + view.setMinimumWidth((int) dimension); + } + }); + + addAttributeProcessor(Attributes.View.Elevation, new DimensionAttributeProcessor() { + @Override + public void setDimension(V view, float dimension) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + view.setElevation(dimension); + } + } + }); + + addAttributeProcessor(Attributes.View.Alpha, new StringAttributeProcessor() { + @Override + public void setString(V view, String value) { + view.setAlpha(ParseHelper.parseFloat(value)); + } + }); + + addAttributeProcessor(Attributes.View.Visibility, new AttributeProcessor() { + @Override + public void handleValue(V view, Value value) { + if (value.isPrimitive() && value.getAsPrimitive().isNumber()) { + // noinspection ResourceType + view.setVisibility(value.getAsInt()); + } else { + process(view, precompile(value, view.getContext(), ((ProteusContext) view.getContext()).getFunctionManager())); + } + } + + @Override + public void handleResource(V view, Resource resource) { + Integer visibility = resource.getInteger(view.getContext()); + //noinspection WrongConstant + view.setVisibility(null != visibility ? visibility : View.GONE); + } + + @Override + public void handleAttributeResource(V view, AttributeResource attribute) { + TypedArray a = attribute.apply(view.getContext()); + //noinspection WrongConstant + view.setVisibility(a.getInt(0, View.GONE)); + } + + @Override + public void handleStyleResource(V view, StyleResource style) { + TypedArray a = style.apply(view.getContext()); + //noinspection WrongConstant + view.setVisibility(a.getInt(0, View.GONE)); + } + + @Override + public Value compile(@Nullable Value value, Context context) { + int visibility = ParseHelper.parseVisibility(value); + return ParseHelper.getVisibility(visibility); + } + }); + + addAttributeProcessor(Attributes.View.Id, new StringAttributeProcessor() { + @Override + public void setString(final V view, String value) { + if (view instanceof ProteusView) { + view.setId(((ProteusView) view).getViewManager().getContext().getInflater().getUniqueViewId(value)); + } - addAttributeProcessor(Attributes.View.Visibility, new AttributeProcessor() { - @Override - public void handleValue(V view, Value value) { - if (value.isPrimitive() && value.getAsPrimitive().isNumber()) { - // noinspection ResourceType - view.setVisibility(value.getAsInt()); + // set view id resource name + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + final String resourceName = value; + view.setAccessibilityDelegate(new View.AccessibilityDelegate() { + @Override + public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { + super.onInitializeAccessibilityNodeInfo(host, info); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + String normalizedResourceName; + if (!TextUtils.isEmpty(resourceName)) { + String id; + if (resourceName.startsWith(ID_STRING_START_PATTERN)) { + id = resourceName.substring(ID_STRING_START_PATTERN.length()); + } else if (resourceName.startsWith(ID_STRING_START_PATTERN1)) { + id = resourceName.substring(ID_STRING_START_PATTERN1.length()); + } else { + id = resourceName; + } + normalizedResourceName = view.getContext().getPackageName() + ID_STRING_NORMALIZED_PATTERN + id; } else { - process(view, precompile(value, view.getContext(), ((ProteusContext) view.getContext()).getFunctionManager())); + normalizedResourceName = ""; } + info.setViewIdResourceName(normalizedResourceName); + } } - - @Override - public void handleResource(V view, Resource resource) { - Integer visibility = resource.getInteger(view.getContext()); - //noinspection WrongConstant - view.setVisibility(null != visibility ? visibility : View.GONE); - } - - @Override - public void handleAttributeResource(V view, AttributeResource attribute) { - TypedArray a = attribute.apply(view.getContext()); - //noinspection WrongConstant - view.setVisibility(a.getInt(0, View.GONE)); - } - - @Override - public void handleStyleResource(V view, StyleResource style) { - TypedArray a = style.apply(view.getContext()); - //noinspection WrongConstant - view.setVisibility(a.getInt(0, View.GONE)); - } - - @Override - public Value compile(@Nullable Value value, Context context) { - int visibility = ParseHelper.parseVisibility(value); - return ParseHelper.getVisibility(visibility); - } - }); - - addAttributeProcessor(Attributes.View.Id, new StringAttributeProcessor() { - @Override - public void setString(final V view, String value) { - if (view instanceof ProteusView) { - view.setId(((ProteusView) view).getViewManager().getContext().getInflater().getUniqueViewId(value)); - } - - // set view id resource name - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { - final String resourceName = value; - view.setAccessibilityDelegate(new View.AccessibilityDelegate() { - @Override - public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { - super.onInitializeAccessibilityNodeInfo(host, info); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { - String normalizedResourceName; - if (!TextUtils.isEmpty(resourceName)) { - String id; - if (resourceName.startsWith(ID_STRING_START_PATTERN)) { - id = resourceName.substring(ID_STRING_START_PATTERN.length()); - } else if (resourceName.startsWith(ID_STRING_START_PATTERN1)) { - id = resourceName.substring(ID_STRING_START_PATTERN1.length()); - } else { - id = resourceName; - } - normalizedResourceName = view.getContext().getPackageName() + ID_STRING_NORMALIZED_PATTERN + id; - } else { - normalizedResourceName = ""; - } - info.setViewIdResourceName(normalizedResourceName); - } - } - }); - } - } - }); - - addAttributeProcessor(Attributes.View.ContentDescription, new StringAttributeProcessor() { - @Override - public void setString(V view, String value) { - view.setContentDescription(value); - } - }); - - addAttributeProcessor(Attributes.View.Clickable, new BooleanAttributeProcessor() { - @Override - public void setBoolean(V view, boolean value) { - view.setClickable(value); - } - }); - - addAttributeProcessor(Attributes.View.Tag, new StringAttributeProcessor() { - @Override - public void setString(V view, String value) { - view.setTag(value); - } - }); - - addAttributeProcessor(Attributes.View.Enabled, new BooleanAttributeProcessor() { - @Override - public void setBoolean(V view, boolean value) { - view.setEnabled(value); - } - }); - - addAttributeProcessor(Attributes.View.Selected, new BooleanAttributeProcessor() { - @Override - public void setBoolean(V view, boolean value) { - view.setSelected(value); - } - }); - - addAttributeProcessor(Attributes.View.Style, new StringAttributeProcessor() { - @Override - public void setString(V view, String value) { - ProteusView.Manager viewManager = ((ProteusView) view).getViewManager(); - ProteusContext context = viewManager.getContext(); - Layout layout = viewManager.getLayout(); - - ViewTypeParser handler = context.getInflater().getParser(layout.type); - - String[] styleSet = value.split(ProteusConstants.STYLE_DELIMITER); - for (String styleName : styleSet) { - Map style = context.getStyle(styleName); - if (null != style) { - process(context.getStyle(styleName), (ProteusView) view, (handler != null ? handler : ViewParser.this)); - } - } - } - - private void process(Map style, ProteusView proteusView, ViewTypeParser handler) { - for (Map.Entry entry : style.entrySet()) { - //noinspection unchecked - handler.handleAttribute(proteusView.getAsView(), handler.getAttributeId(entry.getKey()), entry.getValue()); - } - } - }); - - addAttributeProcessor(Attributes.View.TransitionName, new StringAttributeProcessor() { - @Override - public void setString(V view, String value) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - view.setTransitionName(value); - } - } - }); - - addAttributeProcessor(Attributes.View.RequiresFadingEdge, new StringAttributeProcessor() { - - private final String NONE = "none"; - private final String BOTH = "both"; - private final String VERTICAL = "vertical"; - private final String HORIZONTAL = "horizontal"; - - @Override - public void setString(V view, String value) { - - switch (value) { - case NONE: - view.setVerticalFadingEdgeEnabled(false); - view.setHorizontalFadingEdgeEnabled(false); - break; - case BOTH: - view.setVerticalFadingEdgeEnabled(true); - view.setHorizontalFadingEdgeEnabled(true); - break; - case VERTICAL: - view.setVerticalFadingEdgeEnabled(true); - view.setHorizontalFadingEdgeEnabled(false); - break; - case HORIZONTAL: - view.setVerticalFadingEdgeEnabled(false); - view.setHorizontalFadingEdgeEnabled(true); - break; - default: - view.setVerticalFadingEdgeEnabled(false); - view.setHorizontalFadingEdgeEnabled(false); - break; - } - } - }); - - addAttributeProcessor(Attributes.View.FadingEdgeLength, new StringAttributeProcessor() { - @Override - public void setString(V view, String value) { - view.setFadingEdgeLength(ParseHelper.parseInt(value)); - } - }); - - addAttributeProcessor(Attributes.View.Animation, new TweenAnimationResourceProcessor() { - - @Override - public void setAnimation(V view, Animation animation) { - view.setAnimation(animation); - } - }); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - addAttributeProcessor(Attributes.View.TextAlignment, new StringAttributeProcessor() { - - @SuppressLint("NewApi") - @Override - public void setString(V view, String value) { - - Integer textAlignment = ParseHelper.parseTextAlignment(value); - if (null != textAlignment) { - //noinspection ResourceType - view.setTextAlignment(textAlignment); - } - } - - }); + }); } - - addAttributeProcessor(Attributes.View.Above, createRelativeLayoutRuleProcessor(RelativeLayout.ABOVE)); - addAttributeProcessor(Attributes.View.AlignBaseline, createRelativeLayoutRuleProcessor(RelativeLayout.ALIGN_BASELINE)); - addAttributeProcessor(Attributes.View.AlignBottom, createRelativeLayoutRuleProcessor(RelativeLayout.ALIGN_BOTTOM)); - addAttributeProcessor(Attributes.View.AlignLeft, createRelativeLayoutRuleProcessor(RelativeLayout.ALIGN_LEFT)); - addAttributeProcessor(Attributes.View.AlignRight, createRelativeLayoutRuleProcessor(RelativeLayout.ALIGN_RIGHT)); - addAttributeProcessor(Attributes.View.AlignTop, createRelativeLayoutRuleProcessor(RelativeLayout.ALIGN_TOP)); - addAttributeProcessor(Attributes.View.Below, createRelativeLayoutRuleProcessor(RelativeLayout.BELOW)); - addAttributeProcessor(Attributes.View.ToLeftOf, createRelativeLayoutRuleProcessor(RelativeLayout.LEFT_OF)); - addAttributeProcessor(Attributes.View.ToRightOf, createRelativeLayoutRuleProcessor(RelativeLayout.RIGHT_OF)); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - addAttributeProcessor(Attributes.View.AlignEnd, createRelativeLayoutRuleProcessor(RelativeLayout.ALIGN_END)); - addAttributeProcessor(Attributes.View.AlignStart, createRelativeLayoutRuleProcessor(RelativeLayout.ALIGN_START)); - addAttributeProcessor(Attributes.View.ToEndOf, createRelativeLayoutRuleProcessor(RelativeLayout.END_OF)); - addAttributeProcessor(Attributes.View.ToStartOf, createRelativeLayoutRuleProcessor(RelativeLayout.START_OF)); + } + }); + + addAttributeProcessor(Attributes.View.ContentDescription, new StringAttributeProcessor() { + @Override + public void setString(V view, String value) { + view.setContentDescription(value); + } + }); + + addAttributeProcessor(Attributes.View.Clickable, new BooleanAttributeProcessor() { + @Override + public void setBoolean(V view, boolean value) { + view.setClickable(value); + } + }); + + addAttributeProcessor(Attributes.View.Tag, new StringAttributeProcessor() { + @Override + public void setString(V view, String value) { + view.setTag(value); + } + }); + + addAttributeProcessor(Attributes.View.Enabled, new BooleanAttributeProcessor() { + @Override + public void setBoolean(V view, boolean value) { + view.setEnabled(value); + } + }); + + addAttributeProcessor(Attributes.View.Selected, new BooleanAttributeProcessor() { + @Override + public void setBoolean(V view, boolean value) { + view.setSelected(value); + } + }); + + addAttributeProcessor(Attributes.View.Style, new StringAttributeProcessor() { + @Override + public void setString(V view, String value) { + ProteusView.Manager viewManager = ((ProteusView) view).getViewManager(); + ProteusContext context = viewManager.getContext(); + Layout layout = viewManager.getLayout(); + + ViewTypeParser handler = context.getInflater().getParser(layout.type); + + String[] styleSet = value.split(ProteusConstants.STYLE_DELIMITER); + for (String styleName : styleSet) { + Map style = context.getStyle(styleName); + if (null != style) { + process(context.getStyle(styleName), (ProteusView) view, (handler != null ? handler : ViewParser.this)); + } } + } - addAttributeProcessor(Attributes.View.AlignParentTop, createRelativeLayoutBooleanRuleProcessor(RelativeLayout.ALIGN_PARENT_TOP)); - addAttributeProcessor(Attributes.View.AlignParentRight, createRelativeLayoutBooleanRuleProcessor(RelativeLayout.ALIGN_PARENT_RIGHT)); - addAttributeProcessor(Attributes.View.AlignParentBottom, createRelativeLayoutBooleanRuleProcessor(RelativeLayout.ALIGN_PARENT_BOTTOM)); - addAttributeProcessor(Attributes.View.AlignParentLeft, createRelativeLayoutBooleanRuleProcessor(RelativeLayout.ALIGN_PARENT_LEFT)); - addAttributeProcessor(Attributes.View.CenterHorizontal, createRelativeLayoutBooleanRuleProcessor(RelativeLayout.CENTER_HORIZONTAL)); - addAttributeProcessor(Attributes.View.CenterVertical, createRelativeLayoutBooleanRuleProcessor(RelativeLayout.CENTER_VERTICAL)); - addAttributeProcessor(Attributes.View.CenterInParent, createRelativeLayoutBooleanRuleProcessor(RelativeLayout.CENTER_IN_PARENT)); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - addAttributeProcessor(Attributes.View.AlignParentStart, createRelativeLayoutBooleanRuleProcessor(RelativeLayout.ALIGN_PARENT_START)); - addAttributeProcessor(Attributes.View.AlignParentEnd, createRelativeLayoutBooleanRuleProcessor(RelativeLayout.ALIGN_PARENT_END)); + private void process(Map style, ProteusView proteusView, ViewTypeParser handler) { + for (Map.Entry entry : style.entrySet()) { + //noinspection unchecked + handler.handleAttribute(proteusView.getAsView(), handler.getAttributeId(entry.getKey()), entry.getValue()); + } + } + }); + + addAttributeProcessor(Attributes.View.TransitionName, new StringAttributeProcessor() { + @Override + public void setString(V view, String value) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + view.setTransitionName(value); + } + } + }); + + addAttributeProcessor(Attributes.View.RequiresFadingEdge, new StringAttributeProcessor() { + + private final String NONE = "none"; + private final String BOTH = "both"; + private final String VERTICAL = "vertical"; + private final String HORIZONTAL = "horizontal"; + + @Override + public void setString(V view, String value) { + + switch (value) { + case NONE: + view.setVerticalFadingEdgeEnabled(false); + view.setHorizontalFadingEdgeEnabled(false); + break; + case BOTH: + view.setVerticalFadingEdgeEnabled(true); + view.setHorizontalFadingEdgeEnabled(true); + break; + case VERTICAL: + view.setVerticalFadingEdgeEnabled(true); + view.setHorizontalFadingEdgeEnabled(false); + break; + case HORIZONTAL: + view.setVerticalFadingEdgeEnabled(false); + view.setHorizontalFadingEdgeEnabled(true); + break; + default: + view.setVerticalFadingEdgeEnabled(false); + view.setHorizontalFadingEdgeEnabled(false); + break; + } + } + }); + + addAttributeProcessor(Attributes.View.FadingEdgeLength, new StringAttributeProcessor() { + @Override + public void setString(V view, String value) { + view.setFadingEdgeLength(ParseHelper.parseInt(value)); + } + }); + + addAttributeProcessor(Attributes.View.Animation, new TweenAnimationResourceProcessor() { + + @Override + public void setAnimation(V view, Animation animation) { + view.setAnimation(animation); + } + }); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + addAttributeProcessor(Attributes.View.TextAlignment, new StringAttributeProcessor() { + + @SuppressLint("NewApi") + @Override + public void setString(V view, String value) { + + Integer textAlignment = ParseHelper.parseTextAlignment(value); + if (null != textAlignment) { + //noinspection ResourceType + view.setTextAlignment(textAlignment); + } } - } - @Override - public boolean handleChildren(V view, Value children) { - return false; + }); } - @Override - public boolean addView(ProteusView parent, ProteusView view) { - return false; + addAttributeProcessor(Attributes.View.Above, createRelativeLayoutRuleProcessor(RelativeLayout.ABOVE)); + addAttributeProcessor(Attributes.View.AlignBaseline, createRelativeLayoutRuleProcessor(RelativeLayout.ALIGN_BASELINE)); + addAttributeProcessor(Attributes.View.AlignBottom, createRelativeLayoutRuleProcessor(RelativeLayout.ALIGN_BOTTOM)); + addAttributeProcessor(Attributes.View.AlignLeft, createRelativeLayoutRuleProcessor(RelativeLayout.ALIGN_LEFT)); + addAttributeProcessor(Attributes.View.AlignRight, createRelativeLayoutRuleProcessor(RelativeLayout.ALIGN_RIGHT)); + addAttributeProcessor(Attributes.View.AlignTop, createRelativeLayoutRuleProcessor(RelativeLayout.ALIGN_TOP)); + addAttributeProcessor(Attributes.View.Below, createRelativeLayoutRuleProcessor(RelativeLayout.BELOW)); + addAttributeProcessor(Attributes.View.ToLeftOf, createRelativeLayoutRuleProcessor(RelativeLayout.LEFT_OF)); + addAttributeProcessor(Attributes.View.ToRightOf, createRelativeLayoutRuleProcessor(RelativeLayout.RIGHT_OF)); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + addAttributeProcessor(Attributes.View.AlignEnd, createRelativeLayoutRuleProcessor(RelativeLayout.ALIGN_END)); + addAttributeProcessor(Attributes.View.AlignStart, createRelativeLayoutRuleProcessor(RelativeLayout.ALIGN_START)); + addAttributeProcessor(Attributes.View.ToEndOf, createRelativeLayoutRuleProcessor(RelativeLayout.END_OF)); + addAttributeProcessor(Attributes.View.ToStartOf, createRelativeLayoutRuleProcessor(RelativeLayout.START_OF)); } - private AttributeProcessor createRelativeLayoutRuleProcessor(final int rule) { - return new StringAttributeProcessor() { - @Override - public void setString(V view, String value) { - if (view instanceof ProteusView) { - int id = ((ProteusView) view).getViewManager().getContext().getInflater().getUniqueViewId(value); - ParseHelper.addRelativeLayoutRule(view, rule, id); - } - } - }; - } - - private AttributeProcessor createRelativeLayoutBooleanRuleProcessor(final int rule) { - return new BooleanAttributeProcessor() { - @Override - public void setBoolean(V view, boolean value) { - int trueOrFalse = ParseHelper.parseRelativeLayoutBoolean(value); - ParseHelper.addRelativeLayoutRule(view, rule, trueOrFalse); - } - }; + addAttributeProcessor(Attributes.View.AlignParentTop, createRelativeLayoutBooleanRuleProcessor(RelativeLayout.ALIGN_PARENT_TOP)); + addAttributeProcessor(Attributes.View.AlignParentRight, createRelativeLayoutBooleanRuleProcessor(RelativeLayout.ALIGN_PARENT_RIGHT)); + addAttributeProcessor(Attributes.View.AlignParentBottom, createRelativeLayoutBooleanRuleProcessor(RelativeLayout.ALIGN_PARENT_BOTTOM)); + addAttributeProcessor(Attributes.View.AlignParentLeft, createRelativeLayoutBooleanRuleProcessor(RelativeLayout.ALIGN_PARENT_LEFT)); + addAttributeProcessor(Attributes.View.CenterHorizontal, createRelativeLayoutBooleanRuleProcessor(RelativeLayout.CENTER_HORIZONTAL)); + addAttributeProcessor(Attributes.View.CenterVertical, createRelativeLayoutBooleanRuleProcessor(RelativeLayout.CENTER_VERTICAL)); + addAttributeProcessor(Attributes.View.CenterInParent, createRelativeLayoutBooleanRuleProcessor(RelativeLayout.CENTER_IN_PARENT)); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + addAttributeProcessor(Attributes.View.AlignParentStart, createRelativeLayoutBooleanRuleProcessor(RelativeLayout.ALIGN_PARENT_START)); + addAttributeProcessor(Attributes.View.AlignParentEnd, createRelativeLayoutBooleanRuleProcessor(RelativeLayout.ALIGN_PARENT_END)); } + } + + @Override + public boolean handleChildren(V view, Value children) { + return false; + } + + @Override + public boolean addView(ProteusView parent, ProteusView view) { + return false; + } + + private AttributeProcessor createRelativeLayoutRuleProcessor(final int rule) { + return new StringAttributeProcessor() { + @Override + public void setString(V view, String value) { + if (view instanceof ProteusView) { + int id = ((ProteusView) view).getViewManager().getContext().getInflater().getUniqueViewId(value); + ParseHelper.addRelativeLayoutRule(view, rule, id); + } + } + }; + } + + private AttributeProcessor createRelativeLayoutBooleanRuleProcessor(final int rule) { + return new BooleanAttributeProcessor() { + @Override + public void setBoolean(V view, boolean value) { + int trueOrFalse = ParseHelper.parseRelativeLayoutBoolean(value); + ParseHelper.addRelativeLayoutRule(view, rule, trueOrFalse); + } + }; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ButtonParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ButtonParser.java index 3d740628..21bef431 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ButtonParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ButtonParser.java @@ -34,26 +34,26 @@ */ public class ButtonParser extends ViewTypeParser { - @NonNull - @Override - public String getType() { - return "Button"; - } - - @Nullable - @Override - public String getParentType() { - return "TextView"; - } - - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, - @Nullable ViewGroup parent, int dataIndex) { - return new ProteusButton(context); - } - - @Override - protected void addAttributeProcessors() { - } + @NonNull + @Override + public String getType() { + return "Button"; + } + + @Nullable + @Override + public String getParentType() { + return "TextView"; + } + + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, + @Nullable ViewGroup parent, int dataIndex) { + return new ProteusButton(context); + } + + @Override + protected void addAttributeProcessors() { + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/CheckBoxParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/CheckBoxParser.java index 3260679a..dd1461be 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/CheckBoxParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/CheckBoxParser.java @@ -37,40 +37,40 @@ */ public class CheckBoxParser extends ViewTypeParser { - @NonNull - @Override - public String getType() { - return "CheckBox"; - } + @NonNull + @Override + public String getType() { + return "CheckBox"; + } - @Nullable - @Override - public String getParentType() { - return "Button"; - } + @Nullable + @Override + public String getParentType() { + return "Button"; + } - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, - @Nullable ViewGroup parent, int dataIndex) { - return new ProteusCheckBox(context); - } + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, + @Nullable ViewGroup parent, int dataIndex) { + return new ProteusCheckBox(context); + } - @Override - protected void addAttributeProcessors() { + @Override + protected void addAttributeProcessors() { - addAttributeProcessor(Attributes.CheckBox.Button, new DrawableResourceProcessor() { - @Override - public void setDrawable(T view, Drawable drawable) { - view.setButtonDrawable(drawable); - } - }); + addAttributeProcessor(Attributes.CheckBox.Button, new DrawableResourceProcessor() { + @Override + public void setDrawable(T view, Drawable drawable) { + view.setButtonDrawable(drawable); + } + }); - addAttributeProcessor(Attributes.CheckBox.Checked, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - view.setChecked(Boolean.parseBoolean(value)); - } - }); - } + addAttributeProcessor(Attributes.CheckBox.Checked, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + view.setChecked(Boolean.parseBoolean(value)); + } + }); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/EditTextParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/EditTextParser.java index 2ffbf24f..63341241 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/EditTextParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/EditTextParser.java @@ -34,27 +34,27 @@ */ public class EditTextParser extends ViewTypeParser { - @NonNull - @Override - public String getType() { - return "EditText"; - } - - @Nullable - @Override - public String getParentType() { - return "TextView"; - } - - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, - @Nullable ViewGroup parent, int dataIndex) { - return new ProteusEditText(context); - } - - @Override - protected void addAttributeProcessors() { - - } + @NonNull + @Override + public String getType() { + return "EditText"; + } + + @Nullable + @Override + public String getParentType() { + return "TextView"; + } + + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, + @Nullable ViewGroup parent, int dataIndex) { + return new ProteusEditText(context); + } + + @Override + protected void addAttributeProcessors() { + + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/FrameLayoutParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/FrameLayoutParser.java index fdd5537b..6a2460b7 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/FrameLayoutParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/FrameLayoutParser.java @@ -37,41 +37,41 @@ */ public class FrameLayoutParser extends ViewTypeParser { - @NonNull - @Override - public String getType() { - return "FrameLayout"; - } + @NonNull + @Override + public String getType() { + return "FrameLayout"; + } - @Nullable - @Override - public String getParentType() { - return "ViewGroup"; - } + @Nullable + @Override + public String getParentType() { + return "ViewGroup"; + } - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, - @Nullable ViewGroup parent, int dataIndex) { - return new ProteusAspectRatioFrameLayout(context); - } + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, + @Nullable ViewGroup parent, int dataIndex) { + return new ProteusAspectRatioFrameLayout(context); + } - @Override - protected void addAttributeProcessors() { + @Override + protected void addAttributeProcessors() { - addAttributeProcessor(Attributes.FrameLayout.HeightRatio, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - view.setAspectRatioHeight(ParseHelper.parseInt(value)); + addAttributeProcessor(Attributes.FrameLayout.HeightRatio, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + view.setAspectRatioHeight(ParseHelper.parseInt(value)); - } - }); - addAttributeProcessor(Attributes.FrameLayout.WidthRatio, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - view.setAspectRatioWidth(ParseHelper.parseInt(value)); + } + }); + addAttributeProcessor(Attributes.FrameLayout.WidthRatio, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + view.setAspectRatioWidth(ParseHelper.parseInt(value)); - } - }); - } + } + }); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/HorizontalProgressBarParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/HorizontalProgressBarParser.java index e1d0a86c..04a46cbe 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/HorizontalProgressBarParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/HorizontalProgressBarParser.java @@ -35,27 +35,27 @@ */ public class HorizontalProgressBarParser extends ViewTypeParser { - @NonNull - @Override - public String getType() { - return "HorizontalProgressBar"; - } - - @Nullable - @Override - public String getParentType() { - return "ProgressBar"; - } - - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, - @Nullable ViewGroup parent, int dataIndex) { - return new ProteusHorizontalProgressBar(context); - } - - @Override - protected void addAttributeProcessors() { - } + @NonNull + @Override + public String getType() { + return "HorizontalProgressBar"; + } + + @Nullable + @Override + public String getParentType() { + return "ProgressBar"; + } + + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, + @Nullable ViewGroup parent, int dataIndex) { + return new ProteusHorizontalProgressBar(context); + } + + @Override + protected void addAttributeProcessors() { + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/HorizontalScrollViewParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/HorizontalScrollViewParser.java index fa279508..a1d1cf7f 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/HorizontalScrollViewParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/HorizontalScrollViewParser.java @@ -38,51 +38,51 @@ public class HorizontalScrollViewParser extends ViewTypeParser { - @NonNull - @Override - public String getType() { - return "HorizontalScrollView"; - } + @NonNull + @Override + public String getType() { + return "HorizontalScrollView"; + } - @Nullable - @Override - public String getParentType() { - return "FrameLayout"; - } + @Nullable + @Override + public String getParentType() { + return "FrameLayout"; + } - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, - @Nullable ViewGroup parent, int dataIndex) { - return new ProteusHorizontalScrollView(context); - } + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, + @Nullable ViewGroup parent, int dataIndex) { + return new ProteusHorizontalScrollView(context); + } - @Override - protected void addAttributeProcessors() { + @Override + protected void addAttributeProcessors() { - addAttributeProcessor(Attributes.HorizontalScrollView.FillViewPort, new BooleanAttributeProcessor() { - @Override - public void setBoolean(T view, boolean value) { - view.setFillViewport(value); - } - }); - addAttributeProcessor(Attributes.ScrollView.Scrollbars, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - if ("none".equals(value)) { - view.setHorizontalScrollBarEnabled(false); - view.setVerticalScrollBarEnabled(false); - } else if ("horizontal".equals(value)) { - view.setHorizontalScrollBarEnabled(true); - view.setVerticalScrollBarEnabled(false); - } else if ("vertical".equals(value)) { - view.setHorizontalScrollBarEnabled(false); - view.setVerticalScrollBarEnabled(true); - } else { - view.setHorizontalScrollBarEnabled(false); - view.setVerticalScrollBarEnabled(false); - } - } - }); - } + addAttributeProcessor(Attributes.HorizontalScrollView.FillViewPort, new BooleanAttributeProcessor() { + @Override + public void setBoolean(T view, boolean value) { + view.setFillViewport(value); + } + }); + addAttributeProcessor(Attributes.ScrollView.Scrollbars, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + if ("none".equals(value)) { + view.setHorizontalScrollBarEnabled(false); + view.setVerticalScrollBarEnabled(false); + } else if ("horizontal".equals(value)) { + view.setHorizontalScrollBarEnabled(true); + view.setVerticalScrollBarEnabled(false); + } else if ("vertical".equals(value)) { + view.setHorizontalScrollBarEnabled(false); + view.setVerticalScrollBarEnabled(true); + } else { + view.setHorizontalScrollBarEnabled(false); + view.setVerticalScrollBarEnabled(false); + } + } + }); + } } \ No newline at end of file diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ImageButtonParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ImageButtonParser.java index b73fe471..b1d48b0e 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ImageButtonParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ImageButtonParser.java @@ -33,27 +33,27 @@ */ public class ImageButtonParser extends ViewTypeParser { - @NonNull - @Override - public String getType() { - return "ImageButton"; - } - - @Nullable - @Override - public String getParentType() { - return "ImageView"; - } - - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, - @Nullable ViewGroup parent, int dataIndex) { - return new ProteusImageButton(context); - } - - @Override - protected void addAttributeProcessors() { - - } + @NonNull + @Override + public String getType() { + return "ImageButton"; + } + + @Nullable + @Override + public String getParentType() { + return "ImageView"; + } + + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, + @Nullable ViewGroup parent, int dataIndex) { + return new ProteusImageButton(context); + } + + @Override + protected void addAttributeProcessors() { + + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ImageViewParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ImageViewParser.java index 5b6cf54a..9b7b1eb0 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ImageViewParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ImageViewParser.java @@ -39,54 +39,54 @@ */ public class ImageViewParser extends ViewTypeParser { - @NonNull - @Override - public String getType() { - return "ImageView"; - } + @NonNull + @Override + public String getType() { + return "ImageView"; + } - @Nullable - @Override - public String getParentType() { - return "View"; - } + @Nullable + @Override + public String getParentType() { + return "View"; + } - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, - @Nullable ViewGroup parent, int dataIndex) { - return new ProteusImageView(context); - } + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, + @Nullable ViewGroup parent, int dataIndex) { + return new ProteusImageView(context); + } - @Override - protected void addAttributeProcessors() { + @Override + protected void addAttributeProcessors() { - addAttributeProcessor(Attributes.ImageView.Src, new DrawableResourceProcessor() { - @Override - public void setDrawable(T view, Drawable drawable) { - view.setImageDrawable(drawable); - } - }); + addAttributeProcessor(Attributes.ImageView.Src, new DrawableResourceProcessor() { + @Override + public void setDrawable(T view, Drawable drawable) { + view.setImageDrawable(drawable); + } + }); - addAttributeProcessor(Attributes.ImageView.ScaleType, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - ProteusImageView.ScaleType scaleType; - scaleType = ParseHelper.parseScaleType(value); - if (scaleType != null) - view.setScaleType(scaleType); - } - }); + addAttributeProcessor(Attributes.ImageView.ScaleType, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + ProteusImageView.ScaleType scaleType; + scaleType = ParseHelper.parseScaleType(value); + if (scaleType != null) + view.setScaleType(scaleType); + } + }); - addAttributeProcessor(Attributes.ImageView.AdjustViewBounds, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - if ("true".equals(value)) { - view.setAdjustViewBounds(true); - } else { - view.setAdjustViewBounds(false); - } - } - }); - } + addAttributeProcessor(Attributes.ImageView.AdjustViewBounds, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + if ("true".equals(value)) { + view.setAdjustViewBounds(true); + } else { + view.setAdjustViewBounds(false); + } + } + }); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/LinearLayoutParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/LinearLayoutParser.java index 33045980..d076c714 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/LinearLayoutParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/LinearLayoutParser.java @@ -42,86 +42,86 @@ */ public class LinearLayoutParser extends ViewTypeParser { - @NonNull - @Override - public String getType() { - return "LinearLayout"; - } - - @Nullable - @Override - public String getParentType() { - return "ViewGroup"; - } - - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, - @Nullable ViewGroup parent, int dataIndex) { - return new ProteusLinearLayout(context); - } - - @Override - protected void addAttributeProcessors() { - - addAttributeProcessor(Attributes.LinearLayout.Orientation, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - if ("horizontal".equals(value)) { - view.setOrientation(ProteusLinearLayout.HORIZONTAL); - } else { - view.setOrientation(ProteusLinearLayout.VERTICAL); - } - } - }); - - addAttributeProcessor(Attributes.View.Gravity, new GravityAttributeProcessor() { - @Override - public void setGravity(T view, @Gravity int gravity) { - view.setGravity(gravity); - } - }); - - addAttributeProcessor(Attributes.LinearLayout.Divider, new DrawableResourceProcessor() { - @SuppressLint("NewApi") - @Override - public void setDrawable(T view, Drawable drawable) { - - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) { - view.setDividerDrawable(drawable); - } - } - }); - - addAttributeProcessor(Attributes.LinearLayout.DividerPadding, new DimensionAttributeProcessor() { - @SuppressLint("NewApi") - @Override - public void setDimension(T view, float dimension) { - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) { - view.setDividerPadding((int) dimension); - } - } - }); - - addAttributeProcessor(Attributes.LinearLayout.ShowDividers, new StringAttributeProcessor() { - @SuppressLint("NewApi") - @Override - public void setString(T view, String value) { - - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) { - int dividerMode = ParseHelper.parseDividerMode(value); - // noinspection ResourceType - view.setShowDividers(dividerMode); - } - } - }); - - addAttributeProcessor(Attributes.LinearLayout.WeightSum, new StringAttributeProcessor() { - @SuppressLint("NewApi") - @Override - public void setString(T view, String value) { - view.setWeightSum(ParseHelper.parseFloat(value)); - } - }); - } + @NonNull + @Override + public String getType() { + return "LinearLayout"; + } + + @Nullable + @Override + public String getParentType() { + return "ViewGroup"; + } + + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, + @Nullable ViewGroup parent, int dataIndex) { + return new ProteusLinearLayout(context); + } + + @Override + protected void addAttributeProcessors() { + + addAttributeProcessor(Attributes.LinearLayout.Orientation, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + if ("horizontal".equals(value)) { + view.setOrientation(ProteusLinearLayout.HORIZONTAL); + } else { + view.setOrientation(ProteusLinearLayout.VERTICAL); + } + } + }); + + addAttributeProcessor(Attributes.View.Gravity, new GravityAttributeProcessor() { + @Override + public void setGravity(T view, @Gravity int gravity) { + view.setGravity(gravity); + } + }); + + addAttributeProcessor(Attributes.LinearLayout.Divider, new DrawableResourceProcessor() { + @SuppressLint("NewApi") + @Override + public void setDrawable(T view, Drawable drawable) { + + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) { + view.setDividerDrawable(drawable); + } + } + }); + + addAttributeProcessor(Attributes.LinearLayout.DividerPadding, new DimensionAttributeProcessor() { + @SuppressLint("NewApi") + @Override + public void setDimension(T view, float dimension) { + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) { + view.setDividerPadding((int) dimension); + } + } + }); + + addAttributeProcessor(Attributes.LinearLayout.ShowDividers, new StringAttributeProcessor() { + @SuppressLint("NewApi") + @Override + public void setString(T view, String value) { + + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) { + int dividerMode = ParseHelper.parseDividerMode(value); + // noinspection ResourceType + view.setShowDividers(dividerMode); + } + } + }); + + addAttributeProcessor(Attributes.LinearLayout.WeightSum, new StringAttributeProcessor() { + @SuppressLint("NewApi") + @Override + public void setString(T view, String value) { + view.setWeightSum(ParseHelper.parseFloat(value)); + } + }); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ProgressBarParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ProgressBarParser.java index 6686a5b1..50eddb15 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ProgressBarParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ProgressBarParser.java @@ -53,122 +53,122 @@ */ public class ProgressBarParser extends ViewTypeParser { - @NonNull - @Override - public String getType() { - return "ProgressBar"; - } + @NonNull + @Override + public String getType() { + return "ProgressBar"; + } + + @Nullable + @Override + public String getParentType() { + return "View"; + } + + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, + @Nullable ViewGroup parent, int dataIndex) { + return new ProteusProgressBar(context); + } + + @Override + protected void addAttributeProcessors() { + + addAttributeProcessor(Attributes.ProgressBar.Max, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + view.setMax((int) ParseHelper.parseDouble(value)); + } + }); + addAttributeProcessor(Attributes.ProgressBar.Progress, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + view.setProgress((int) ParseHelper.parseDouble(value)); + } + }); + + addAttributeProcessor(Attributes.ProgressBar.ProgressTint, new AttributeProcessor() { + @Override + public void handleValue(T view, Value value) { + if (!value.isObject()) { + return; + } + int background = Color.TRANSPARENT; + int progress = Color.TRANSPARENT; + ObjectValue object = value.getAsObject(); + String string = object.getAsString("background"); + if (string != null) { + background = ParseHelper.parseColor(string); + } + string = object.getAsString("progress"); + if (string != null) { + progress = ParseHelper.parseColor(string); + } - @Nullable - @Override - public String getParentType() { - return "View"; - } + view.setProgressDrawable(getLayerDrawable(progress, background)); + } + + @Override + public void handleResource(T view, Resource resource) { + Drawable d = resource.getDrawable(view.getContext()); + view.setProgressDrawable(d); + } + + @Override + public void handleAttributeResource(T view, AttributeResource attribute) { + TypedArray a = attribute.apply(view.getContext()); + view.setProgressDrawable(a.getDrawable(0)); + } + + @Override + public void handleStyleResource(T view, StyleResource style) { + TypedArray a = style.apply(view.getContext()); + view.setProgressDrawable(a.getDrawable(0)); + } + }); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + addAttributeProcessor(Attributes.ProgressBar.SecondaryProgressTint, new ColorResourceProcessor() { + @Override + public void setColor(T view, int color) { - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, - @Nullable ViewGroup parent, int dataIndex) { - return new ProteusProgressBar(context); - } + } - @Override - protected void addAttributeProcessors() { - - addAttributeProcessor(Attributes.ProgressBar.Max, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - view.setMax((int) ParseHelper.parseDouble(value)); - } - }); - addAttributeProcessor(Attributes.ProgressBar.Progress, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - view.setProgress((int) ParseHelper.parseDouble(value)); - } - }); - - addAttributeProcessor(Attributes.ProgressBar.ProgressTint, new AttributeProcessor() { - @Override - public void handleValue(T view, Value value) { - if (!value.isObject()) { - return; - } - int background = Color.TRANSPARENT; - int progress = Color.TRANSPARENT; - ObjectValue object = value.getAsObject(); - String string = object.getAsString("background"); - if (string != null) { - background = ParseHelper.parseColor(string); - } - string = object.getAsString("progress"); - if (string != null) { - progress = ParseHelper.parseColor(string); - } - - view.setProgressDrawable(getLayerDrawable(progress, background)); - } - - @Override - public void handleResource(T view, Resource resource) { - Drawable d = resource.getDrawable(view.getContext()); - view.setProgressDrawable(d); - } - - @Override - public void handleAttributeResource(T view, AttributeResource attribute) { - TypedArray a = attribute.apply(view.getContext()); - view.setProgressDrawable(a.getDrawable(0)); - } - - @Override - public void handleStyleResource(T view, StyleResource style) { - TypedArray a = style.apply(view.getContext()); - view.setProgressDrawable(a.getDrawable(0)); - } - }); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - addAttributeProcessor(Attributes.ProgressBar.SecondaryProgressTint, new ColorResourceProcessor() { - @Override - public void setColor(T view, int color) { - - } - - @Override - public void setColor(T view, ColorStateList colors) { - //noinspection AndroidLintNewApi - view.setSecondaryProgressTintList(colors); - } - }); + @Override + public void setColor(T view, ColorStateList colors) { + //noinspection AndroidLintNewApi + view.setSecondaryProgressTintList(colors); } + }); + } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - addAttributeProcessor(Attributes.ProgressBar.IndeterminateTint, new ColorResourceProcessor() { - @Override - public void setColor(T view, int color) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + addAttributeProcessor(Attributes.ProgressBar.IndeterminateTint, new ColorResourceProcessor() { + @Override + public void setColor(T view, int color) { - } + } - @Override - public void setColor(T view, ColorStateList colors) { - //noinspection AndroidLintNewApi - view.setIndeterminateTintList(colors); - } - }); + @Override + public void setColor(T view, ColorStateList colors) { + //noinspection AndroidLintNewApi + view.setIndeterminateTintList(colors); } + }); } + } - Drawable getLayerDrawable(int progress, int background) { - ShapeDrawable shape = new ShapeDrawable(); - shape.getPaint().setStyle(Paint.Style.FILL); - shape.getPaint().setColor(background); + Drawable getLayerDrawable(int progress, int background) { + ShapeDrawable shape = new ShapeDrawable(); + shape.getPaint().setStyle(Paint.Style.FILL); + shape.getPaint().setColor(background); - ShapeDrawable shapeD = new ShapeDrawable(); - shapeD.getPaint().setStyle(Paint.Style.FILL); - shapeD.getPaint().setColor(progress); - ClipDrawable clipDrawable = new ClipDrawable(shapeD, Gravity.LEFT, ClipDrawable.HORIZONTAL); + ShapeDrawable shapeD = new ShapeDrawable(); + shapeD.getPaint().setStyle(Paint.Style.FILL); + shapeD.getPaint().setColor(progress); + ClipDrawable clipDrawable = new ClipDrawable(shapeD, Gravity.LEFT, ClipDrawable.HORIZONTAL); - return new LayerDrawable(new Drawable[]{shape, clipDrawable}); - } + return new LayerDrawable(new Drawable[]{shape, clipDrawable}); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/RatingBarParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/RatingBarParser.java index 684cf623..b488d9dc 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/RatingBarParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/RatingBarParser.java @@ -40,64 +40,64 @@ */ public class RatingBarParser extends ViewTypeParser { - @NonNull - @Override - public String getType() { - return "RatingBar"; - } + @NonNull + @Override + public String getType() { + return "RatingBar"; + } - @Nullable - @Override - public String getParentType() { - return "View"; - } + @Nullable + @Override + public String getParentType() { + return "View"; + } - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, - @Nullable ViewGroup parent, int dataIndex) { - return new ProteusFixedRatingBar(context); - } + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, + @Nullable ViewGroup parent, int dataIndex) { + return new ProteusFixedRatingBar(context); + } - @Override - protected void addAttributeProcessors() { + @Override + protected void addAttributeProcessors() { - addAttributeProcessor(Attributes.RatingBar.NumStars, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - view.setNumStars(ParseHelper.parseInt(value)); - } - }); - addAttributeProcessor(Attributes.RatingBar.Rating, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - view.setRating(ParseHelper.parseFloat(value)); - } - }); - addAttributeProcessor(Attributes.RatingBar.IsIndicator, new BooleanAttributeProcessor() { - @Override - public void setBoolean(T view, boolean value) { - view.setIsIndicator(value); - } - }); - addAttributeProcessor(Attributes.RatingBar.StepSize, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - view.setStepSize(ParseHelper.parseFloat(value)); - } - }); - addAttributeProcessor(Attributes.RatingBar.MinHeight, new DimensionAttributeProcessor() { - @Override - public void setDimension(T view, float dimension) { - view.setMinimumHeight((int) dimension); - } - }); - addAttributeProcessor(Attributes.RatingBar.ProgressDrawable, new DrawableResourceProcessor() { - @Override - public void setDrawable(T view, Drawable drawable) { - drawable = view.getTiledDrawable(drawable, false); - view.setProgressDrawable(drawable); - } - }); - } + addAttributeProcessor(Attributes.RatingBar.NumStars, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + view.setNumStars(ParseHelper.parseInt(value)); + } + }); + addAttributeProcessor(Attributes.RatingBar.Rating, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + view.setRating(ParseHelper.parseFloat(value)); + } + }); + addAttributeProcessor(Attributes.RatingBar.IsIndicator, new BooleanAttributeProcessor() { + @Override + public void setBoolean(T view, boolean value) { + view.setIsIndicator(value); + } + }); + addAttributeProcessor(Attributes.RatingBar.StepSize, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + view.setStepSize(ParseHelper.parseFloat(value)); + } + }); + addAttributeProcessor(Attributes.RatingBar.MinHeight, new DimensionAttributeProcessor() { + @Override + public void setDimension(T view, float dimension) { + view.setMinimumHeight((int) dimension); + } + }); + addAttributeProcessor(Attributes.RatingBar.ProgressDrawable, new DrawableResourceProcessor() { + @Override + public void setDrawable(T view, Drawable drawable) { + drawable = view.getTiledDrawable(drawable, false); + view.setProgressDrawable(drawable); + } + }); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/RelativeLayoutParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/RelativeLayoutParser.java index d1c57205..81b6066a 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/RelativeLayoutParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/RelativeLayoutParser.java @@ -36,33 +36,33 @@ */ public class RelativeLayoutParser extends ViewTypeParser { - @NonNull - @Override - public String getType() { - return "RelativeLayout"; - } + @NonNull + @Override + public String getType() { + return "RelativeLayout"; + } - @Nullable - @Override - public String getParentType() { - return "ViewGroup"; - } + @Nullable + @Override + public String getParentType() { + return "ViewGroup"; + } - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, - @Nullable ViewGroup parent, int dataIndex) { - return new ProteusRelativeLayout(context); - } + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, + @Nullable ViewGroup parent, int dataIndex) { + return new ProteusRelativeLayout(context); + } - @Override - protected void addAttributeProcessors() { + @Override + protected void addAttributeProcessors() { - addAttributeProcessor(Attributes.View.Gravity, new GravityAttributeProcessor() { - @Override - public void setGravity(T view, @Gravity int gravity) { - view.setGravity(gravity); - } - }); - } + addAttributeProcessor(Attributes.View.Gravity, new GravityAttributeProcessor() { + @Override + public void setGravity(T view, @Gravity int gravity) { + view.setGravity(gravity); + } + }); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ScrollViewParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ScrollViewParser.java index a5205c65..bb8c3275 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ScrollViewParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ScrollViewParser.java @@ -36,45 +36,45 @@ */ public class ScrollViewParser extends ViewTypeParser { - @NonNull - @Override - public String getType() { - return "ScrollView"; - } + @NonNull + @Override + public String getType() { + return "ScrollView"; + } - @Nullable - @Override - public String getParentType() { - return "FrameLayout"; - } + @Nullable + @Override + public String getParentType() { + return "FrameLayout"; + } - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, - @Nullable ViewGroup parent, int dataIndex) { - return new ProteusScrollView(context); - } + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, + @Nullable ViewGroup parent, int dataIndex) { + return new ProteusScrollView(context); + } - @Override - protected void addAttributeProcessors() { + @Override + protected void addAttributeProcessors() { - addAttributeProcessor(Attributes.ScrollView.Scrollbars, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - if ("none".equals(value)) { - view.setHorizontalScrollBarEnabled(false); - view.setVerticalScrollBarEnabled(false); - } else if ("horizontal".equals(value)) { - view.setHorizontalScrollBarEnabled(true); - view.setVerticalScrollBarEnabled(false); - } else if ("vertical".equals(value)) { - view.setHorizontalScrollBarEnabled(false); - view.setVerticalScrollBarEnabled(true); - } else { - view.setHorizontalScrollBarEnabled(false); - view.setVerticalScrollBarEnabled(false); - } - } - }); - } + addAttributeProcessor(Attributes.ScrollView.Scrollbars, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + if ("none".equals(value)) { + view.setHorizontalScrollBarEnabled(false); + view.setVerticalScrollBarEnabled(false); + } else if ("horizontal".equals(value)) { + view.setHorizontalScrollBarEnabled(true); + view.setVerticalScrollBarEnabled(false); + } else if ("vertical".equals(value)) { + view.setHorizontalScrollBarEnabled(false); + view.setVerticalScrollBarEnabled(true); + } else { + view.setHorizontalScrollBarEnabled(false); + view.setVerticalScrollBarEnabled(false); + } + } + }); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/TextViewParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/TextViewParser.java index 316e70c7..20708ddb 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/TextViewParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/TextViewParser.java @@ -48,210 +48,210 @@ */ public class TextViewParser extends ViewTypeParser { - @NonNull - @Override - public String getType() { - return "TextView"; - } - - @Nullable - @Override - public String getParentType() { - return "View"; - } - - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, - @Nullable ViewGroup parent, int dataIndex) { - return new ProteusTextView(context); - } - - @Override - protected void addAttributeProcessors() { - - addAttributeProcessor(Attributes.TextView.HTML, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - view.setText(Html.fromHtml(value, Html.FROM_HTML_MODE_LEGACY)); - } else { - //noinspection deprecation - view.setText(Html.fromHtml(value)); - } - } - }); - addAttributeProcessor(Attributes.TextView.Text, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - view.setText(value); - } - }); - - addAttributeProcessor(Attributes.TextView.DrawablePadding, new DimensionAttributeProcessor() { - @Override - public void setDimension(T view, float dimension) { - view.setCompoundDrawablePadding((int) dimension); - } - }); - - addAttributeProcessor(Attributes.TextView.TextSize, new DimensionAttributeProcessor() { - @Override - public void setDimension(T view, float dimension) { - view.setTextSize(TypedValue.COMPLEX_UNIT_PX, dimension); - } - }); - addAttributeProcessor(Attributes.TextView.Gravity, new GravityAttributeProcessor() { - @Override - public void setGravity(T view, @Gravity int gravity) { - view.setGravity(gravity); - } - }); - - addAttributeProcessor(Attributes.TextView.TextColor, new ColorResourceProcessor() { - - @Override - public void setColor(T view, int color) { - view.setTextColor(color); - } - - @Override - public void setColor(T view, ColorStateList colors) { - view.setTextColor(colors); - } - }); - - addAttributeProcessor(Attributes.TextView.TextColorHint, new ColorResourceProcessor() { - - @Override - public void setColor(T view, int color) { - view.setHintTextColor(color); - } - - @Override - public void setColor(T view, ColorStateList colors) { - view.setHintTextColor(colors); - } - }); - - addAttributeProcessor(Attributes.TextView.TextColorLink, new ColorResourceProcessor() { - - @Override - public void setColor(T view, int color) { - view.setLinkTextColor(color); - } - - @Override - public void setColor(T view, ColorStateList colors) { - view.setLinkTextColor(colors); - } - }); - - addAttributeProcessor(Attributes.TextView.TextColorHighLight, new ColorResourceProcessor() { - - @Override - public void setColor(T view, int color) { - view.setHighlightColor(color); - } - - @Override - public void setColor(T view, ColorStateList colors) { - // - } - }); - - addAttributeProcessor(Attributes.TextView.DrawableLeft, new DrawableResourceProcessor() { - @Override - public void setDrawable(T view, Drawable drawable) { - Drawable[] compoundDrawables = view.getCompoundDrawables(); - view.setCompoundDrawablesWithIntrinsicBounds(drawable, compoundDrawables[1], compoundDrawables[2], compoundDrawables[3]); - } - }); - addAttributeProcessor(Attributes.TextView.DrawableTop, new DrawableResourceProcessor() { - @Override - public void setDrawable(T view, Drawable drawable) { - Drawable[] compoundDrawables = view.getCompoundDrawables(); - view.setCompoundDrawablesWithIntrinsicBounds(compoundDrawables[0], drawable, compoundDrawables[2], compoundDrawables[3]); - } - }); - addAttributeProcessor(Attributes.TextView.DrawableRight, new DrawableResourceProcessor() { - @Override - public void setDrawable(T view, Drawable drawable) { - Drawable[] compoundDrawables = view.getCompoundDrawables(); - view.setCompoundDrawablesWithIntrinsicBounds(drawable, compoundDrawables[1], drawable, compoundDrawables[3]); - } - }); - addAttributeProcessor(Attributes.TextView.DrawableBottom, new DrawableResourceProcessor() { - @Override - public void setDrawable(T view, Drawable drawable) { - Drawable[] compoundDrawables = view.getCompoundDrawables(); - view.setCompoundDrawablesWithIntrinsicBounds(drawable, compoundDrawables[1], compoundDrawables[2], drawable); - } - }); - - addAttributeProcessor(Attributes.TextView.MaxLines, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - view.setMaxLines(ParseHelper.parseInt(value)); - } - }); - - addAttributeProcessor(Attributes.TextView.Ellipsize, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - Enum ellipsize = ParseHelper.parseEllipsize(value); - view.setEllipsize((android.text.TextUtils.TruncateAt) ellipsize); - } - }); - - addAttributeProcessor(Attributes.TextView.PaintFlags, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - if (value.equals("strike")) - view.setPaintFlags(view.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); - } - }); - - addAttributeProcessor(Attributes.TextView.Prefix, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - view.setText(value + view.getText()); - } - }); - - addAttributeProcessor(Attributes.TextView.Suffix, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - view.setText(view.getText() + value); - } - }); - - addAttributeProcessor(Attributes.TextView.TextStyle, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - int typeface = ParseHelper.parseTextStyle(value); - view.setTypeface(Typeface.defaultFromStyle(typeface)); - } - }); - - addAttributeProcessor(Attributes.TextView.SingleLine, new BooleanAttributeProcessor() { - @Override - public void setBoolean(T view, boolean value) { - view.setSingleLine(value); - } - }); - - addAttributeProcessor(Attributes.TextView.TextAllCaps, new BooleanAttributeProcessor() { - @Override - public void setBoolean(T view, boolean value) { - view.setAllCaps(value); - } - }); - addAttributeProcessor(Attributes.TextView.Hint, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - view.setHint(value); - } - }); - } + @NonNull + @Override + public String getType() { + return "TextView"; + } + + @Nullable + @Override + public String getParentType() { + return "View"; + } + + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, + @Nullable ViewGroup parent, int dataIndex) { + return new ProteusTextView(context); + } + + @Override + protected void addAttributeProcessors() { + + addAttributeProcessor(Attributes.TextView.HTML, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + view.setText(Html.fromHtml(value, Html.FROM_HTML_MODE_LEGACY)); + } else { + //noinspection deprecation + view.setText(Html.fromHtml(value)); + } + } + }); + addAttributeProcessor(Attributes.TextView.Text, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + view.setText(value); + } + }); + + addAttributeProcessor(Attributes.TextView.DrawablePadding, new DimensionAttributeProcessor() { + @Override + public void setDimension(T view, float dimension) { + view.setCompoundDrawablePadding((int) dimension); + } + }); + + addAttributeProcessor(Attributes.TextView.TextSize, new DimensionAttributeProcessor() { + @Override + public void setDimension(T view, float dimension) { + view.setTextSize(TypedValue.COMPLEX_UNIT_PX, dimension); + } + }); + addAttributeProcessor(Attributes.TextView.Gravity, new GravityAttributeProcessor() { + @Override + public void setGravity(T view, @Gravity int gravity) { + view.setGravity(gravity); + } + }); + + addAttributeProcessor(Attributes.TextView.TextColor, new ColorResourceProcessor() { + + @Override + public void setColor(T view, int color) { + view.setTextColor(color); + } + + @Override + public void setColor(T view, ColorStateList colors) { + view.setTextColor(colors); + } + }); + + addAttributeProcessor(Attributes.TextView.TextColorHint, new ColorResourceProcessor() { + + @Override + public void setColor(T view, int color) { + view.setHintTextColor(color); + } + + @Override + public void setColor(T view, ColorStateList colors) { + view.setHintTextColor(colors); + } + }); + + addAttributeProcessor(Attributes.TextView.TextColorLink, new ColorResourceProcessor() { + + @Override + public void setColor(T view, int color) { + view.setLinkTextColor(color); + } + + @Override + public void setColor(T view, ColorStateList colors) { + view.setLinkTextColor(colors); + } + }); + + addAttributeProcessor(Attributes.TextView.TextColorHighLight, new ColorResourceProcessor() { + + @Override + public void setColor(T view, int color) { + view.setHighlightColor(color); + } + + @Override + public void setColor(T view, ColorStateList colors) { + // + } + }); + + addAttributeProcessor(Attributes.TextView.DrawableLeft, new DrawableResourceProcessor() { + @Override + public void setDrawable(T view, Drawable drawable) { + Drawable[] compoundDrawables = view.getCompoundDrawables(); + view.setCompoundDrawablesWithIntrinsicBounds(drawable, compoundDrawables[1], compoundDrawables[2], compoundDrawables[3]); + } + }); + addAttributeProcessor(Attributes.TextView.DrawableTop, new DrawableResourceProcessor() { + @Override + public void setDrawable(T view, Drawable drawable) { + Drawable[] compoundDrawables = view.getCompoundDrawables(); + view.setCompoundDrawablesWithIntrinsicBounds(compoundDrawables[0], drawable, compoundDrawables[2], compoundDrawables[3]); + } + }); + addAttributeProcessor(Attributes.TextView.DrawableRight, new DrawableResourceProcessor() { + @Override + public void setDrawable(T view, Drawable drawable) { + Drawable[] compoundDrawables = view.getCompoundDrawables(); + view.setCompoundDrawablesWithIntrinsicBounds(drawable, compoundDrawables[1], drawable, compoundDrawables[3]); + } + }); + addAttributeProcessor(Attributes.TextView.DrawableBottom, new DrawableResourceProcessor() { + @Override + public void setDrawable(T view, Drawable drawable) { + Drawable[] compoundDrawables = view.getCompoundDrawables(); + view.setCompoundDrawablesWithIntrinsicBounds(drawable, compoundDrawables[1], compoundDrawables[2], drawable); + } + }); + + addAttributeProcessor(Attributes.TextView.MaxLines, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + view.setMaxLines(ParseHelper.parseInt(value)); + } + }); + + addAttributeProcessor(Attributes.TextView.Ellipsize, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + Enum ellipsize = ParseHelper.parseEllipsize(value); + view.setEllipsize((android.text.TextUtils.TruncateAt) ellipsize); + } + }); + + addAttributeProcessor(Attributes.TextView.PaintFlags, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + if (value.equals("strike")) + view.setPaintFlags(view.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); + } + }); + + addAttributeProcessor(Attributes.TextView.Prefix, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + view.setText(value + view.getText()); + } + }); + + addAttributeProcessor(Attributes.TextView.Suffix, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + view.setText(view.getText() + value); + } + }); + + addAttributeProcessor(Attributes.TextView.TextStyle, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + int typeface = ParseHelper.parseTextStyle(value); + view.setTypeface(Typeface.defaultFromStyle(typeface)); + } + }); + + addAttributeProcessor(Attributes.TextView.SingleLine, new BooleanAttributeProcessor() { + @Override + public void setBoolean(T view, boolean value) { + view.setSingleLine(value); + } + }); + + addAttributeProcessor(Attributes.TextView.TextAllCaps, new BooleanAttributeProcessor() { + @Override + public void setBoolean(T view, boolean value) { + view.setAllCaps(value); + } + }); + addAttributeProcessor(Attributes.TextView.Hint, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + view.setHint(value); + } + }); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ViewGroupParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ViewGroupParser.java index 87f856f5..7e816cee 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ViewGroupParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ViewGroupParser.java @@ -27,9 +27,9 @@ import com.flipkart.android.proteus.ProteusContext; import com.flipkart.android.proteus.ProteusLayoutInflater; import com.flipkart.android.proteus.ProteusView; -import com.flipkart.android.proteus.managers.ViewGroupManager; import com.flipkart.android.proteus.ViewTypeParser; import com.flipkart.android.proteus.exceptions.ProteusInflateException; +import com.flipkart.android.proteus.managers.ViewGroupManager; import com.flipkart.android.proteus.processor.AttributeProcessor; import com.flipkart.android.proteus.processor.BooleanAttributeProcessor; import com.flipkart.android.proteus.processor.StringAttributeProcessor; @@ -48,185 +48,185 @@ public class ViewGroupParser extends ViewTypeParser { - private static final String LAYOUT_MODE_CLIP_BOUNDS = "clipBounds"; - private static final String LAYOUT_MODE_OPTICAL_BOUNDS = "opticalBounds"; - - @NonNull - @Override - public String getType() { - return "ViewGroup"; - } - - @Nullable - @Override - public String getParentType() { - return "View"; + private static final String LAYOUT_MODE_CLIP_BOUNDS = "clipBounds"; + private static final String LAYOUT_MODE_OPTICAL_BOUNDS = "opticalBounds"; + + @NonNull + @Override + public String getType() { + return "ViewGroup"; + } + + @Nullable + @Override + public String getParentType() { + return "View"; + } + + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, + @Nullable ViewGroup parent, int dataIndex) { + return new ProteusAspectRatioFrameLayout(context); + } + + @NonNull + @Override + public ProteusView.Manager createViewManager(@NonNull ProteusContext context, @NonNull ProteusView view, @NonNull Layout layout, + @NonNull ObjectValue data, @Nullable ViewTypeParser caller, @Nullable ViewGroup parent, + int dataIndex) { + DataContext dataContext = createDataContext(context, layout, data, parent, dataIndex); + return new ViewGroupManager(context, null != caller ? caller : this, view.getAsView(), layout, dataContext); + } + + @Override + protected void addAttributeProcessors() { + + addAttributeProcessor(Attributes.ViewGroup.ClipChildren, new BooleanAttributeProcessor() { + @Override + public void setBoolean(T view, boolean value) { + view.setClipChildren(value); + } + }); + + addAttributeProcessor(Attributes.ViewGroup.ClipToPadding, new BooleanAttributeProcessor() { + @Override + public void setBoolean(T view, boolean value) { + view.setClipToPadding(value); + } + }); + + addAttributeProcessor(Attributes.ViewGroup.LayoutMode, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + if (LAYOUT_MODE_CLIP_BOUNDS.equals(value)) { + view.setLayoutMode(ViewGroup.LAYOUT_MODE_CLIP_BOUNDS); + } else if (LAYOUT_MODE_OPTICAL_BOUNDS.equals(value)) { + view.setLayoutMode(ViewGroup.LAYOUT_MODE_OPTICAL_BOUNDS); + } + } + } + }); + + addAttributeProcessor(Attributes.ViewGroup.SplitMotionEvents, new BooleanAttributeProcessor() { + @Override + public void setBoolean(T view, boolean value) { + view.setMotionEventSplittingEnabled(value); + } + }); + + addAttributeProcessor(Attributes.ViewGroup.Children, new AttributeProcessor() { + @Override + public void handleBinding(T view, Binding value) { + handleDataBoundChildren(view, value); + } + + @Override + public void handleValue(T view, Value value) { + handleChildren(view, value); + } + + @Override + public void handleResource(T view, Resource resource) { + throw new IllegalArgumentException("children cannot be a resource"); + } + + @Override + public void handleAttributeResource(T view, AttributeResource attribute) { + throw new IllegalArgumentException("children cannot be a resource"); + } + + @Override + public void handleStyleResource(T view, StyleResource style) { + throw new IllegalArgumentException("children cannot be a style attribute"); + } + }); + } + + @Override + public boolean handleChildren(T view, Value children) { + ProteusView proteusView = ((ProteusView) view); + ProteusView.Manager viewManager = proteusView.getViewManager(); + ProteusLayoutInflater layoutInflater = viewManager.getContext().getInflater(); + ObjectValue data = viewManager.getDataContext().getData(); + int dataIndex = viewManager.getDataContext().getIndex(); + + if (children.isArray()) { + ProteusView child; + Iterator iterator = children.getAsArray().iterator(); + Value element; + while (iterator.hasNext()) { + element = iterator.next(); + if (!element.isLayout()) { + throw new ProteusInflateException("attribute 'children' must be an array of 'Layout' objects"); + } + child = layoutInflater.inflate(element.getAsLayout(), data, view, dataIndex); + addView(proteusView, child); + } } - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, - @Nullable ViewGroup parent, int dataIndex) { - return new ProteusAspectRatioFrameLayout(context); - } + return true; + } - @NonNull - @Override - public ProteusView.Manager createViewManager(@NonNull ProteusContext context, @NonNull ProteusView view, @NonNull Layout layout, - @NonNull ObjectValue data, @Nullable ViewTypeParser caller, @Nullable ViewGroup parent, - int dataIndex) { - DataContext dataContext = createDataContext(context, layout, data, parent, dataIndex); - return new ViewGroupManager(context, null != caller ? caller : this, view.getAsView(), layout, dataContext); - } + protected void handleDataBoundChildren(T view, Binding value) { + ProteusView parent = ((ProteusView) view); + ViewGroupManager manager = (ViewGroupManager) parent.getViewManager(); + DataContext dataContext = manager.getDataContext(); + ObjectValue config = ((NestedBinding) value).getValue().getAsObject(); - @Override - protected void addAttributeProcessors() { - - addAttributeProcessor(Attributes.ViewGroup.ClipChildren, new BooleanAttributeProcessor() { - @Override - public void setBoolean(T view, boolean value) { - view.setClipChildren(value); - } - }); - - addAttributeProcessor(Attributes.ViewGroup.ClipToPadding, new BooleanAttributeProcessor() { - @Override - public void setBoolean(T view, boolean value) { - view.setClipToPadding(value); - } - }); - - addAttributeProcessor(Attributes.ViewGroup.LayoutMode, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { - if (LAYOUT_MODE_CLIP_BOUNDS.equals(value)) { - view.setLayoutMode(ViewGroup.LAYOUT_MODE_CLIP_BOUNDS); - } else if (LAYOUT_MODE_OPTICAL_BOUNDS.equals(value)) { - view.setLayoutMode(ViewGroup.LAYOUT_MODE_OPTICAL_BOUNDS); - } - } - } - }); - - addAttributeProcessor(Attributes.ViewGroup.SplitMotionEvents, new BooleanAttributeProcessor() { - @Override - public void setBoolean(T view, boolean value) { - view.setMotionEventSplittingEnabled(value); - } - }); - - addAttributeProcessor(Attributes.ViewGroup.Children, new AttributeProcessor() { - @Override - public void handleBinding(T view, Binding value) { - handleDataBoundChildren(view, value); - } - - @Override - public void handleValue(T view, Value value) { - handleChildren(view, value); - } - - @Override - public void handleResource(T view, Resource resource) { - throw new IllegalArgumentException("children cannot be a resource"); - } - - @Override - public void handleAttributeResource(T view, AttributeResource attribute) { - throw new IllegalArgumentException("children cannot be a resource"); - } - - @Override - public void handleStyleResource(T view, StyleResource style) { - throw new IllegalArgumentException("children cannot be a style attribute"); - } - }); - } + Binding collection = config.getAsBinding(ProteusConstants.COLLECTION); + Layout layout = config.getAsLayout(ProteusConstants.LAYOUT); - @Override - public boolean handleChildren(T view, Value children) { - ProteusView proteusView = ((ProteusView) view); - ProteusView.Manager viewManager = proteusView.getViewManager(); - ProteusLayoutInflater layoutInflater = viewManager.getContext().getInflater(); - ObjectValue data = viewManager.getDataContext().getData(); - int dataIndex = viewManager.getDataContext().getIndex(); - - if (children.isArray()) { - ProteusView child; - Iterator iterator = children.getAsArray().iterator(); - Value element; - while (iterator.hasNext()) { - element = iterator.next(); - if (!element.isLayout()) { - throw new ProteusInflateException("attribute 'children' must be an array of 'Layout' objects"); - } - child = layoutInflater.inflate(element.getAsLayout(), data, view, dataIndex); - addView(proteusView, child); - } - } + manager.hasDataBoundChildren = true; - return true; + if (null == layout || null == collection) { + throw new ProteusInflateException("'collection' and 'layout' are mandatory for attribute:'children'"); } - protected void handleDataBoundChildren(T view, Binding value) { - ProteusView parent = ((ProteusView) view); - ViewGroupManager manager = (ViewGroupManager) parent.getViewManager(); - DataContext dataContext = manager.getDataContext(); - ObjectValue config = ((NestedBinding) value).getValue().getAsObject(); - - Binding collection = config.getAsBinding(ProteusConstants.COLLECTION); - Layout layout = config.getAsLayout(ProteusConstants.LAYOUT); - - manager.hasDataBoundChildren = true; - - if (null == layout || null == collection) { - throw new ProteusInflateException("'collection' and 'layout' are mandatory for attribute:'children'"); - } - - Value dataset = collection.getAsBinding().evaluate(view.getContext(), dataContext.getData(), dataContext.getIndex()); - if (dataset.isNull()) { - return; - } + Value dataset = collection.getAsBinding().evaluate(view.getContext(), dataContext.getData(), dataContext.getIndex()); + if (dataset.isNull()) { + return; + } - if (!dataset.isArray()) { - throw new ProteusInflateException("'collection' in attribute:'children' must be NULL or Array"); - } + if (!dataset.isArray()) { + throw new ProteusInflateException("'collection' in attribute:'children' must be NULL or Array"); + } - int length = dataset.getAsArray().size(); - int count = view.getChildCount(); - ObjectValue data = dataContext.getData(); - ProteusLayoutInflater inflater = manager.getContext().getInflater(); - ProteusView child; - View temp; - - if (count > length) { - while (count > length) { - count--; - view.removeViewAt(count); - } - } + int length = dataset.getAsArray().size(); + int count = view.getChildCount(); + ObjectValue data = dataContext.getData(); + ProteusLayoutInflater inflater = manager.getContext().getInflater(); + ProteusView child; + View temp; + + if (count > length) { + while (count > length) { + count--; + view.removeViewAt(count); + } + } - for (int index = 0; index < length; index++) { - if (index < count) { - temp = view.getChildAt(index); - if (temp instanceof ProteusView) { - ((ProteusView) temp).getViewManager().update(data); - } - } else { - //noinspection ConstantConditions : We want to throw an exception if the layout is null - child = inflater.inflate(layout, data, view, index); - addView(parent, child); - } + for (int index = 0; index < length; index++) { + if (index < count) { + temp = view.getChildAt(index); + if (temp instanceof ProteusView) { + ((ProteusView) temp).getViewManager().update(data); } + } else { + //noinspection ConstantConditions : We want to throw an exception if the layout is null + child = inflater.inflate(layout, data, view, index); + addView(parent, child); + } } + } - @Override - public boolean addView(ProteusView parent, ProteusView view) { - if (parent instanceof ViewGroup) { - ((ViewGroup) parent).addView(view.getAsView()); - return true; - } - return false; + @Override + public boolean addView(ProteusView parent, ProteusView view) { + if (parent instanceof ViewGroup) { + ((ViewGroup) parent).addView(view.getAsView()); + return true; } + return false; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/WebViewParser.java b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/WebViewParser.java index c88e2ec9..4cea44d1 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/WebViewParser.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/WebViewParser.java @@ -35,39 +35,39 @@ */ public class WebViewParser extends ViewTypeParser { - @NonNull - @Override - public String getType() { - return "WebView"; - } + @NonNull + @Override + public String getType() { + return "WebView"; + } - @Nullable - @Override - public String getParentType() { - return "View"; - } + @Nullable + @Override + public String getParentType() { + return "View"; + } - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, - @Nullable ViewGroup parent, int dataIndex) { - return new ProteusWebView(context); - } + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, + @Nullable ViewGroup parent, int dataIndex) { + return new ProteusWebView(context); + } - @Override - protected void addAttributeProcessors() { + @Override + protected void addAttributeProcessors() { - addAttributeProcessor(Attributes.WebView.Url, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - view.loadUrl(value); - } - }); - addAttributeProcessor(Attributes.WebView.HTML, new StringAttributeProcessor() { - @Override - public void setString(T view, String value) { - view.loadData(value, "text/html", "UTF-8"); - } - }); - } + addAttributeProcessor(Attributes.WebView.Url, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + view.loadUrl(value); + } + }); + addAttributeProcessor(Attributes.WebView.HTML, new StringAttributeProcessor() { + @Override + public void setString(T view, String value) { + view.loadData(value, "text/html", "UTF-8"); + } + }); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/AttributeProcessor.java b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/AttributeProcessor.java index dc313e54..3ee095e3 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/AttributeProcessor.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/AttributeProcessor.java @@ -38,118 +38,118 @@ */ public abstract class AttributeProcessor { - public static Value evaluate(final Context context, final Value input, final Value data, final int index) { - final Value[] output = new Value[1]; - - AttributeProcessor processor = new AttributeProcessor() { - - @Override - public void handleBinding(View view, Binding binding) { - output[0] = binding.evaluate(context, data, index); - } - - @Override - public void handleValue(View view, Value value) { - output[0] = value; - } - - @Override - public void handleResource(View view, Resource resource) { - output[0] = new Primitive(resource.getString(context)); - } - - @Override - public void handleAttributeResource(View view, AttributeResource attribute) { - output[0] = new Primitive(attribute.apply(context).getString(0)); - } - - @Override - public void handleStyleResource(View view, StyleResource style) { - output[0] = new Primitive(style.apply(context).getString(0)); - } - }; - - //noinspection unchecked - processor.process(null, input); - - return output[0]; + public static Value evaluate(final Context context, final Value input, final Value data, final int index) { + final Value[] output = new Value[1]; + + AttributeProcessor processor = new AttributeProcessor() { + + @Override + public void handleBinding(View view, Binding binding) { + output[0] = binding.evaluate(context, data, index); + } + + @Override + public void handleValue(View view, Value value) { + output[0] = value; + } + + @Override + public void handleResource(View view, Resource resource) { + output[0] = new Primitive(resource.getString(context)); + } + + @Override + public void handleAttributeResource(View view, AttributeResource attribute) { + output[0] = new Primitive(attribute.apply(context).getString(0)); + } + + @Override + public void handleStyleResource(View view, StyleResource style) { + output[0] = new Primitive(style.apply(context).getString(0)); + } + }; + + //noinspection unchecked + processor.process(null, input); + + return output[0]; + } + + @Nullable + public static Value staticPreCompile(Primitive value, Context context, FunctionManager manager) { + String string = value.getAsString(); + if (Binding.isBindingValue(string)) { + return Binding.valueOf(string, context, manager); + } else if (Resource.isResource(string)) { + return Resource.valueOf(string, null, context); + } else if (AttributeResource.isAttributeResource(string)) { + return AttributeResource.valueOf(string, context); + } else if (StyleResource.isStyleResource(string)) { + return StyleResource.valueOf(string, context); } - - @Nullable - public static Value staticPreCompile(Primitive value, Context context, FunctionManager manager) { - String string = value.getAsString(); - if (Binding.isBindingValue(string)) { - return Binding.valueOf(string, context, manager); - } else if (Resource.isResource(string)) { - return Resource.valueOf(string, null, context); - } else if (AttributeResource.isAttributeResource(string)) { - return AttributeResource.valueOf(string, context); - } else if (StyleResource.isStyleResource(string)) { - return StyleResource.valueOf(string, context); - } - return null; + return null; + } + + @Nullable + public static Value staticPreCompile(ObjectValue object, Context context, FunctionManager manager) { + Value binding = object.get(NestedBinding.NESTED_BINDING_KEY); + if (null != binding) { + return NestedBinding.valueOf(binding); } - - @Nullable - public static Value staticPreCompile(ObjectValue object, Context context, FunctionManager manager) { - Value binding = object.get(NestedBinding.NESTED_BINDING_KEY); - if (null != binding) { - return NestedBinding.valueOf(binding); - } - return null; - } - - @Nullable - public static Value staticPreCompile(Value value, Context context, FunctionManager manager) { - Value compiled = null; - if (value.isPrimitive()) { - compiled = staticPreCompile(value.getAsPrimitive(), context, manager); - } else if (value.isObject()) { - compiled = staticPreCompile(value.getAsObject(), context, manager); - } else if (value.isBinding() || value.isResource() || value.isAttributeResource() || value.isStyleResource()) { - return value; - } - return compiled; + return null; + } + + @Nullable + public static Value staticPreCompile(Value value, Context context, FunctionManager manager) { + Value compiled = null; + if (value.isPrimitive()) { + compiled = staticPreCompile(value.getAsPrimitive(), context, manager); + } else if (value.isObject()) { + compiled = staticPreCompile(value.getAsObject(), context, manager); + } else if (value.isBinding() || value.isResource() || value.isAttributeResource() || value.isStyleResource()) { + return value; } - - public void process(V view, Value value) { - if (value.isBinding()) { - handleBinding(view, value.getAsBinding()); - } else if (value.isResource()) { - handleResource(view, value.getAsResource()); - } else if (value.isAttributeResource()) { - handleAttributeResource(view, value.getAsAttributeResource()); - } else if (value.isStyleResource()) { - handleStyleResource(view, value.getAsStyleResource()); - } else { - handleValue(view, value); - } + return compiled; + } + + public void process(V view, Value value) { + if (value.isBinding()) { + handleBinding(view, value.getAsBinding()); + } else if (value.isResource()) { + handleResource(view, value.getAsResource()); + } else if (value.isAttributeResource()) { + handleAttributeResource(view, value.getAsAttributeResource()); + } else if (value.isStyleResource()) { + handleStyleResource(view, value.getAsStyleResource()); + } else { + handleValue(view, value); } + } - public void handleBinding(V view, Binding value) { - DataContext dataContext = ((ProteusView) view).getViewManager().getDataContext(); - Value resolved = evaluate(value, view.getContext(), dataContext.getData(), dataContext.getIndex()); - handleValue(view, resolved); - } + public void handleBinding(V view, Binding value) { + DataContext dataContext = ((ProteusView) view).getViewManager().getDataContext(); + Value resolved = evaluate(value, view.getContext(), dataContext.getData(), dataContext.getIndex()); + handleValue(view, resolved); + } - public abstract void handleValue(V view, Value value); + public abstract void handleValue(V view, Value value); - public abstract void handleResource(V view, Resource resource); + public abstract void handleResource(V view, Resource resource); - public abstract void handleAttributeResource(V view, AttributeResource attribute); + public abstract void handleAttributeResource(V view, AttributeResource attribute); - public abstract void handleStyleResource(V view, StyleResource style); + public abstract void handleStyleResource(V view, StyleResource style); - public Value precompile(Value value, Context context, FunctionManager manager) { - Value compiled = staticPreCompile(value, context, manager); - return null != compiled ? compiled : compile(value, context); - } + public Value precompile(Value value, Context context, FunctionManager manager) { + Value compiled = staticPreCompile(value, context, manager); + return null != compiled ? compiled : compile(value, context); + } - public Value compile(@Nullable Value value, Context context) { - return value; - } + public Value compile(@Nullable Value value, Context context) { + return value; + } - protected Value evaluate(Binding binding, Context context, Value data, int index) { - return binding.evaluate(context, data, index); - } + protected Value evaluate(Binding binding, Context context, Value data, int index) { + return binding.evaluate(context, data, index); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/BooleanAttributeProcessor.java b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/BooleanAttributeProcessor.java index 2182215f..32f9da11 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/BooleanAttributeProcessor.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/BooleanAttributeProcessor.java @@ -37,37 +37,37 @@ public abstract class BooleanAttributeProcessor extends AttributeProcessor { - @Override - public void handleValue(V view, Value value) { - if (value.isPrimitive() && value.getAsPrimitive().isBoolean()) { - setBoolean(view, value.getAsPrimitive().getAsBoolean()); - } else { - process(view, precompile(value, view.getContext(), ((ProteusContext) view.getContext()).getFunctionManager())); - } + @Override + public void handleValue(V view, Value value) { + if (value.isPrimitive() && value.getAsPrimitive().isBoolean()) { + setBoolean(view, value.getAsPrimitive().getAsBoolean()); + } else { + process(view, precompile(value, view.getContext(), ((ProteusContext) view.getContext()).getFunctionManager())); } + } - @Override - public void handleResource(V view, Resource resource) { - Boolean bool = resource.getBoolean(view.getContext()); - setBoolean(view, null != bool ? bool : false); - } + @Override + public void handleResource(V view, Resource resource) { + Boolean bool = resource.getBoolean(view.getContext()); + setBoolean(view, null != bool ? bool : false); + } - @Override - public void handleAttributeResource(V view, AttributeResource attribute) { - TypedArray a = attribute.apply(view.getContext()); - setBoolean(view, a.getBoolean(0, false)); - } + @Override + public void handleAttributeResource(V view, AttributeResource attribute) { + TypedArray a = attribute.apply(view.getContext()); + setBoolean(view, a.getBoolean(0, false)); + } - @Override - public void handleStyleResource(V view, StyleResource style) { - TypedArray a = style.apply(view.getContext()); - setBoolean(view, a.getBoolean(0, false)); - } + @Override + public void handleStyleResource(V view, StyleResource style) { + TypedArray a = style.apply(view.getContext()); + setBoolean(view, a.getBoolean(0, false)); + } - public abstract void setBoolean(V view, boolean value); + public abstract void setBoolean(V view, boolean value); - @Override - public Value compile(@Nullable Value value, Context context) { - return ParseHelper.parseBoolean(value) ? ProteusConstants.TRUE : ProteusConstants.FALSE; - } + @Override + public Value compile(@Nullable Value value, Context context) { + return ParseHelper.parseBoolean(value) ? ProteusConstants.TRUE : ProteusConstants.FALSE; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/ColorResourceProcessor.java b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/ColorResourceProcessor.java index c9fcede3..a8c7f2c9 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/ColorResourceProcessor.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/ColorResourceProcessor.java @@ -32,98 +32,98 @@ public abstract class ColorResourceProcessor extends AttributeProcessor { - public static Color.Result evaluate(Value value, ProteusView view) { - final Color.Result[] result = new Color.Result[1]; - ColorResourceProcessor processor = new ColorResourceProcessor() { - @Override - public void setColor(View view, int color) { - result[0] = Color.Result.color(color); - } - - @Override - public void setColor(View view, ColorStateList colors) { - result[0] = Color.Result.colors(colors); - } - }; - processor.process(view.getAsView(), value); - return result[0]; + public static Color.Result evaluate(Value value, ProteusView view) { + final Color.Result[] result = new Color.Result[1]; + ColorResourceProcessor processor = new ColorResourceProcessor() { + @Override + public void setColor(View view, int color) { + result[0] = Color.Result.color(color); + } + + @Override + public void setColor(View view, ColorStateList colors) { + result[0] = Color.Result.colors(colors); + } + }; + processor.process(view.getAsView(), value); + return result[0]; + } + + public static Value staticCompile(@Nullable Value value, Context context) { + if (null == value) { + return Color.Int.BLACK; } - - public static Value staticCompile(@Nullable Value value, Context context) { - if (null == value) { - return Color.Int.BLACK; - } - if (value.isColor()) { - return value; - } else if (value.isObject()) { - return Color.valueOf(value.getAsObject(), context); - } else if (value.isPrimitive()) { - Value precompiled = AttributeProcessor.staticPreCompile(value.getAsPrimitive(), context, null); - if (null != precompiled) { - return precompiled; - } - return Color.valueOf(value.getAsString(), Color.Int.BLACK); - } else { - return Color.Int.BLACK; - } - } - - @Override - public void handleValue(final V view, Value value) { - if (value.isColor()) { - apply(view, value.getAsColor()); - } else { - process(view, precompile(value, view.getContext(), ((ProteusContext) view.getContext()).getFunctionManager())); - } - } - - @Override - public void handleResource(V view, Resource resource) { - ColorStateList colors = resource.getColorStateList(view.getContext()); - if (null != colors) { - setColor(view, colors); - } else { - Integer color = resource.getColor(view.getContext()); - setColor(view, null == color ? Color.Int.BLACK.value : color); - } + if (value.isColor()) { + return value; + } else if (value.isObject()) { + return Color.valueOf(value.getAsObject(), context); + } else if (value.isPrimitive()) { + Value precompiled = AttributeProcessor.staticPreCompile(value.getAsPrimitive(), context, null); + if (null != precompiled) { + return precompiled; + } + return Color.valueOf(value.getAsString(), Color.Int.BLACK); + } else { + return Color.Int.BLACK; } - - @Override - public void handleAttributeResource(V view, AttributeResource attribute) { - TypedArray a = attribute.apply(view.getContext()); - set(view, a); + } + + @Override + public void handleValue(final V view, Value value) { + if (value.isColor()) { + apply(view, value.getAsColor()); + } else { + process(view, precompile(value, view.getContext(), ((ProteusContext) view.getContext()).getFunctionManager())); } - - @Override - public void handleStyleResource(V view, StyleResource style) { - TypedArray a = style.apply(view.getContext()); - set(view, a); + } + + @Override + public void handleResource(V view, Resource resource) { + ColorStateList colors = resource.getColorStateList(view.getContext()); + if (null != colors) { + setColor(view, colors); + } else { + Integer color = resource.getColor(view.getContext()); + setColor(view, null == color ? Color.Int.BLACK.value : color); } - - private void set(V view, TypedArray a) { - ColorStateList colors = a.getColorStateList(0); - if (null != colors) { - setColor(view, colors); - } else { - setColor(view, a.getColor(0, Color.Int.BLACK.value)); - } + } + + @Override + public void handleAttributeResource(V view, AttributeResource attribute) { + TypedArray a = attribute.apply(view.getContext()); + set(view, a); + } + + @Override + public void handleStyleResource(V view, StyleResource style) { + TypedArray a = style.apply(view.getContext()); + set(view, a); + } + + private void set(V view, TypedArray a) { + ColorStateList colors = a.getColorStateList(0); + if (null != colors) { + setColor(view, colors); + } else { + setColor(view, a.getColor(0, Color.Int.BLACK.value)); } - - private void apply(V view, Color color) { - Color.Result result = color.apply(view.getContext()); - if (null != result.colors) { - setColor(view, result.colors); - } else { - setColor(view, result.color); - } + } + + private void apply(V view, Color color) { + Color.Result result = color.apply(view.getContext()); + if (null != result.colors) { + setColor(view, result.colors); + } else { + setColor(view, result.color); } + } - public abstract void setColor(V view, int color); + public abstract void setColor(V view, int color); - public abstract void setColor(V view, ColorStateList colors); + public abstract void setColor(V view, ColorStateList colors); - @Override - public Value compile(@Nullable Value value, Context context) { - return staticCompile(value, context); - } + @Override + public Value compile(@Nullable Value value, Context context) { + return staticCompile(value, context); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/DimensionAttributeProcessor.java b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/DimensionAttributeProcessor.java index 64f2fc85..8e5899e3 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/DimensionAttributeProcessor.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/DimensionAttributeProcessor.java @@ -35,72 +35,72 @@ */ public abstract class DimensionAttributeProcessor extends AttributeProcessor { - public static float evaluate(Value value, ProteusView view) { - if (value == null) { - return Dimension.ZERO.apply(view.getAsView().getContext()); - } - - final float[] result = new float[1]; - DimensionAttributeProcessor processor = new DimensionAttributeProcessor() { - @Override - public void setDimension(View view, float dimension) { - result[0] = dimension; - } - }; - processor.process(view.getAsView(), value); - - return result[0]; + public static float evaluate(Value value, ProteusView view) { + if (value == null) { + return Dimension.ZERO.apply(view.getAsView().getContext()); } - public static Value staticCompile(@Nullable Value value, Context context) { - if (null == value || !value.isPrimitive()) { - return Dimension.ZERO; - } - if (value.isDimension()) { - return value; - } - Value precompiled = AttributeProcessor.staticPreCompile(value.getAsPrimitive(), context, null); - if (null != precompiled) { - return precompiled; - } - return Dimension.valueOf(value.getAsString()); + final float[] result = new float[1]; + DimensionAttributeProcessor processor = new DimensionAttributeProcessor() { + @Override + public void setDimension(View view, float dimension) { + result[0] = dimension; + } + }; + processor.process(view.getAsView(), value); + + return result[0]; + } + + public static Value staticCompile(@Nullable Value value, Context context) { + if (null == value || !value.isPrimitive()) { + return Dimension.ZERO; } - - @Override - public final void handleValue(T view, Value value) { - if (value.isDimension()) { - setDimension(view, value.getAsDimension().apply(view.getContext())); - } else if (value.isPrimitive()) { - process(view, precompile(value, view.getContext(), ((ProteusContext) view.getContext()).getFunctionManager())); - } - } - - @Override - public void handleResource(T view, Resource resource) { - Float dimension = resource.getDimension(view.getContext()); - setDimension(view, null == dimension ? 0 : dimension); - } - - @Override - public void handleAttributeResource(T view, AttributeResource attribute) { - TypedArray a = attribute.apply(view.getContext()); - setDimension(view, a.getDimensionPixelSize(0, 0)); + if (value.isDimension()) { + return value; } - - @Override - public void handleStyleResource(T view, StyleResource style) { - TypedArray a = style.apply(view.getContext()); - setDimension(view, a.getDimensionPixelSize(0, 0)); + Value precompiled = AttributeProcessor.staticPreCompile(value.getAsPrimitive(), context, null); + if (null != precompiled) { + return precompiled; } - - /** - * @param view View - */ - public abstract void setDimension(T view, float dimension); - - @Override - public Value compile(@Nullable Value value, Context context) { - return staticCompile(value, context); + return Dimension.valueOf(value.getAsString()); + } + + @Override + public final void handleValue(T view, Value value) { + if (value.isDimension()) { + setDimension(view, value.getAsDimension().apply(view.getContext())); + } else if (value.isPrimitive()) { + process(view, precompile(value, view.getContext(), ((ProteusContext) view.getContext()).getFunctionManager())); } + } + + @Override + public void handleResource(T view, Resource resource) { + Float dimension = resource.getDimension(view.getContext()); + setDimension(view, null == dimension ? 0 : dimension); + } + + @Override + public void handleAttributeResource(T view, AttributeResource attribute) { + TypedArray a = attribute.apply(view.getContext()); + setDimension(view, a.getDimensionPixelSize(0, 0)); + } + + @Override + public void handleStyleResource(T view, StyleResource style) { + TypedArray a = style.apply(view.getContext()); + setDimension(view, a.getDimensionPixelSize(0, 0)); + } + + /** + * @param view View + */ + public abstract void setDimension(T view, float dimension); + + @Override + public Value compile(@Nullable Value value, Context context) { + return staticCompile(value, context); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/DrawableResourceProcessor.java b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/DrawableResourceProcessor.java index 192674f1..18f21ae4 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/DrawableResourceProcessor.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/DrawableResourceProcessor.java @@ -36,92 +36,92 @@ */ public abstract class DrawableResourceProcessor extends AttributeProcessor { - @Nullable - public static Drawable evaluate(Value value, ProteusView view) { - if (null == value) { - return null; - } - final Drawable[] d = new Drawable[1]; - DrawableResourceProcessor processor = new DrawableResourceProcessor() { - @Override - public void setDrawable(View view, Drawable drawable) { - d[0] = drawable; - } - }; - processor.process(view.getAsView(), value); - return d[0]; + @Nullable + public static Drawable evaluate(Value value, ProteusView view) { + if (null == value) { + return null; } + final Drawable[] d = new Drawable[1]; + DrawableResourceProcessor processor = new DrawableResourceProcessor() { + @Override + public void setDrawable(View view, Drawable drawable) { + d[0] = drawable; + } + }; + processor.process(view.getAsView(), value); + return d[0]; + } - public static Value staticCompile(@Nullable Value value, Context context) { - if (null == value) { - return DrawableValue.ColorValue.BLACK; - } - if (value.isDrawable()) { - return value; - } else if (value.isPrimitive()) { - Value precompiled = AttributeProcessor.staticPreCompile(value.getAsPrimitive(), context, null); - if (null != precompiled) { - return precompiled; - } - return DrawableValue.valueOf(value.getAsString(), context); - } else if (value.isObject()) { - return DrawableValue.valueOf(value.getAsObject(), context); - } else { - return DrawableValue.ColorValue.BLACK; - } + public static Value staticCompile(@Nullable Value value, Context context) { + if (null == value) { + return DrawableValue.ColorValue.BLACK; + } + if (value.isDrawable()) { + return value; + } else if (value.isPrimitive()) { + Value precompiled = AttributeProcessor.staticPreCompile(value.getAsPrimitive(), context, null); + if (null != precompiled) { + return precompiled; + } + return DrawableValue.valueOf(value.getAsString(), context); + } else if (value.isObject()) { + return DrawableValue.valueOf(value.getAsObject(), context); + } else { + return DrawableValue.ColorValue.BLACK; } + } - @Override - public void handleValue(final V view, Value value) { - if (value.isDrawable()) { - DrawableValue d = value.getAsDrawable(); - if (null != d) { - ProteusLayoutInflater.ImageLoader loader = ((ProteusView) view).getViewManager().getContext().getLoader(); - d.apply((ProteusView) view, view.getContext(), loader, new DrawableValue.Callback() { - @Override - public void apply(Drawable drawable) { - if (null != drawable) { - setDrawable(view, drawable); - } - } - }); + @Override + public void handleValue(final V view, Value value) { + if (value.isDrawable()) { + DrawableValue d = value.getAsDrawable(); + if (null != d) { + ProteusLayoutInflater.ImageLoader loader = ((ProteusView) view).getViewManager().getContext().getLoader(); + d.apply((ProteusView) view, view.getContext(), loader, new DrawableValue.Callback() { + @Override + public void apply(Drawable drawable) { + if (null != drawable) { + setDrawable(view, drawable); } - } else { - process(view, precompile(value, view.getContext(), ((ProteusContext) view.getContext()).getFunctionManager())); - } + } + }); + } + } else { + process(view, precompile(value, view.getContext(), ((ProteusContext) view.getContext()).getFunctionManager())); } + } - @Override - public void handleResource(V view, Resource resource) { - Drawable d = resource.getDrawable(view.getContext()); - if (null != d) { - setDrawable(view, d); - } + @Override + public void handleResource(V view, Resource resource) { + Drawable d = resource.getDrawable(view.getContext()); + if (null != d) { + setDrawable(view, d); } + } - @Override - public void handleAttributeResource(V view, AttributeResource attribute) { - TypedArray a = attribute.apply(view.getContext()); - set(view, a); - } + @Override + public void handleAttributeResource(V view, AttributeResource attribute) { + TypedArray a = attribute.apply(view.getContext()); + set(view, a); + } - @Override - public void handleStyleResource(V view, StyleResource style) { - TypedArray a = style.apply(view.getContext()); - set(view, a); - } + @Override + public void handleStyleResource(V view, StyleResource style) { + TypedArray a = style.apply(view.getContext()); + set(view, a); + } - private void set(V view, TypedArray a) { - Drawable d = a.getDrawable(0); - if (null != d) { - setDrawable(view, d); - } + private void set(V view, TypedArray a) { + Drawable d = a.getDrawable(0); + if (null != d) { + setDrawable(view, d); } + } - public abstract void setDrawable(V view, Drawable drawable); + public abstract void setDrawable(V view, Drawable drawable); - @Override - public Value compile(@Nullable Value value, Context context) { - return staticCompile(value, context); - } + @Override + public Value compile(@Nullable Value value, Context context) { + return staticCompile(value, context); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/EventProcessor.java b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/EventProcessor.java index 01a28530..75fbc664 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/EventProcessor.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/EventProcessor.java @@ -39,37 +39,37 @@ public abstract class EventProcessor extends AttributeProcessor { - @Override - public void handleValue(T view, Value value) { - setOnEventListener(view, value); - } + @Override + public void handleValue(T view, Value value) { + setOnEventListener(view, value); + } - @Override - public void handleResource(T view, Resource resource) { - setOnEventListener(view, resource); - } + @Override + public void handleResource(T view, Resource resource) { + setOnEventListener(view, resource); + } - @Override - public void handleAttributeResource(T view, AttributeResource attribute) { - setOnEventListener(view, attribute); - } + @Override + public void handleAttributeResource(T view, AttributeResource attribute) { + setOnEventListener(view, attribute); + } - @Override - public void handleStyleResource(T view, StyleResource style) { - setOnEventListener(view, style); - } + @Override + public void handleStyleResource(T view, StyleResource style) { + setOnEventListener(view, style); + } - public abstract void setOnEventListener(T view, Value value); + public abstract void setOnEventListener(T view, Value value); - /** - * @param event - * @param value - * @param view - */ - public void trigger(String event, Value value, ProteusView view) { - ProteusLayoutInflater.Callback callback = view.getViewManager().getContext().getCallback(); - if (null != callback) { - callback.onEvent(event, value, view); - } + /** + * @param event + * @param value + * @param view + */ + public void trigger(String event, Value value, ProteusView view) { + ProteusLayoutInflater.Callback callback = view.getViewManager().getContext().getCallback(); + if (null != callback) { + callback.onEvent(event, value, view); } + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/GravityAttributeProcessor.java b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/GravityAttributeProcessor.java index 3d9f8782..83a8a50b 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/GravityAttributeProcessor.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/GravityAttributeProcessor.java @@ -47,70 +47,70 @@ public abstract class GravityAttributeProcessor extends AttributeProcessor { - public static final Primitive NO_GRAVITY = new Primitive(android.view.Gravity.NO_GRAVITY); - - @Override - public void handleValue(V view, Value value) { - int gravity = android.view.Gravity.NO_GRAVITY; - if (value.isPrimitive() && value.getAsPrimitive().isNumber()) { - gravity = value.getAsInt(); - } else if (value.isPrimitive()) { - gravity = ParseHelper.parseGravity(value.getAsString()); - } - //noinspection WrongConstant - setGravity(view, gravity); + public static final Primitive NO_GRAVITY = new Primitive(android.view.Gravity.NO_GRAVITY); + + @Override + public void handleValue(V view, Value value) { + int gravity = android.view.Gravity.NO_GRAVITY; + if (value.isPrimitive() && value.getAsPrimitive().isNumber()) { + gravity = value.getAsInt(); + } else if (value.isPrimitive()) { + gravity = ParseHelper.parseGravity(value.getAsString()); } - - @Override - public void handleResource(V view, Resource resource) { - Integer gravity = resource.getInteger(view.getContext()); - //noinspection WrongConstant - setGravity(view, null != gravity ? gravity : android.view.Gravity.NO_GRAVITY); - } - - @Override - public void handleAttributeResource(V view, AttributeResource attribute) { - TypedArray a = attribute.apply(view.getContext()); - set(view, a); - } - - @Override - public void handleStyleResource(V view, StyleResource style) { - TypedArray a = style.apply(view.getContext()); - set(view, a); - } - - private void set(V view, TypedArray a) { - //noinspection WrongConstant - setGravity(view, a.getInt(0, android.view.Gravity.NO_GRAVITY)); - } - - public abstract void setGravity(V view, @Gravity int gravity); - - @Override - public Value compile(@Nullable Value value, Context context) { - if (null == value) { - return NO_GRAVITY; - } - return ParseHelper.getGravity(value.getAsString()); - } - - @IntDef({android.view.Gravity.NO_GRAVITY, - android.view.Gravity.TOP, - android.view.Gravity.BOTTOM, - android.view.Gravity.LEFT, - android.view.Gravity.RIGHT, - android.view.Gravity.START, - android.view.Gravity.END, - android.view.Gravity.CENTER_VERTICAL, - android.view.Gravity.FILL_VERTICAL, - android.view.Gravity.CENTER_HORIZONTAL, - android.view.Gravity.FILL_HORIZONTAL, - android.view.Gravity.CENTER, - android.view.Gravity.FILL}) - @Retention(RetentionPolicy.SOURCE) - @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE}) - public @interface Gravity { + //noinspection WrongConstant + setGravity(view, gravity); + } + + @Override + public void handleResource(V view, Resource resource) { + Integer gravity = resource.getInteger(view.getContext()); + //noinspection WrongConstant + setGravity(view, null != gravity ? gravity : android.view.Gravity.NO_GRAVITY); + } + + @Override + public void handleAttributeResource(V view, AttributeResource attribute) { + TypedArray a = attribute.apply(view.getContext()); + set(view, a); + } + + @Override + public void handleStyleResource(V view, StyleResource style) { + TypedArray a = style.apply(view.getContext()); + set(view, a); + } + + private void set(V view, TypedArray a) { + //noinspection WrongConstant + setGravity(view, a.getInt(0, android.view.Gravity.NO_GRAVITY)); + } + + public abstract void setGravity(V view, @Gravity int gravity); + + @Override + public Value compile(@Nullable Value value, Context context) { + if (null == value) { + return NO_GRAVITY; } + return ParseHelper.getGravity(value.getAsString()); + } + + @IntDef({android.view.Gravity.NO_GRAVITY, + android.view.Gravity.TOP, + android.view.Gravity.BOTTOM, + android.view.Gravity.LEFT, + android.view.Gravity.RIGHT, + android.view.Gravity.START, + android.view.Gravity.END, + android.view.Gravity.CENTER_VERTICAL, + android.view.Gravity.FILL_VERTICAL, + android.view.Gravity.CENTER_HORIZONTAL, + android.view.Gravity.FILL_HORIZONTAL, + android.view.Gravity.CENTER, + android.view.Gravity.FILL}) + @Retention(RetentionPolicy.SOURCE) + @Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE}) + public @interface Gravity { + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/NumberAttributeProcessor.java b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/NumberAttributeProcessor.java index 78064692..beee493c 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/NumberAttributeProcessor.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/NumberAttributeProcessor.java @@ -32,28 +32,28 @@ public abstract class NumberAttributeProcessor extends AttributeProcessor { - @Override - public void handleValue(V view, Value value) { - if (value.isPrimitive()) { - setNumber(view, value.getAsPrimitive().getAsNumber()); - } + @Override + public void handleValue(V view, Value value) { + if (value.isPrimitive()) { + setNumber(view, value.getAsPrimitive().getAsNumber()); } + } - @Override - public void handleResource(V view, Resource resource) { - Integer number = resource.getInteger(view.getContext()); - setNumber(view, null != number ? number : 0); - } + @Override + public void handleResource(V view, Resource resource) { + Integer number = resource.getInteger(view.getContext()); + setNumber(view, null != number ? number : 0); + } - @Override - public void handleAttributeResource(V view, AttributeResource attribute) { - setNumber(view, attribute.apply(view.getContext()).getFloat(0, 0f)); - } + @Override + public void handleAttributeResource(V view, AttributeResource attribute) { + setNumber(view, attribute.apply(view.getContext()).getFloat(0, 0f)); + } - @Override - public void handleStyleResource(V view, StyleResource style) { - setNumber(view, style.apply(view.getContext()).getFloat(0, 0f)); - } + @Override + public void handleStyleResource(V view, StyleResource style) { + setNumber(view, style.apply(view.getContext()).getFloat(0, 0f)); + } - public abstract void setNumber(V view, @NonNull Number value); + public abstract void setNumber(V view, @NonNull Number value); } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/StringAttributeProcessor.java b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/StringAttributeProcessor.java index a08d86f7..4ed7b040 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/StringAttributeProcessor.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/StringAttributeProcessor.java @@ -33,47 +33,47 @@ */ public abstract class StringAttributeProcessor extends AttributeProcessor { - /** - * @param view View - * @param value - */ - @Override - public void handleValue(V view, Value value) { - if (value.isPrimitive() || value.isNull()) { - setString(view, value.getAsString()); - } else { - setString(view, "[Object]"); - } + /** + * @param view View + * @param value + */ + @Override + public void handleValue(V view, Value value) { + if (value.isPrimitive() || value.isNull()) { + setString(view, value.getAsString()); + } else { + setString(view, "[Object]"); } + } - @Override - public void handleResource(V view, Resource resource) { - String string = resource.getString(view.getContext()); - setString(view, null == string ? ProteusConstants.EMPTY : string); - } + @Override + public void handleResource(V view, Resource resource) { + String string = resource.getString(view.getContext()); + setString(view, null == string ? ProteusConstants.EMPTY : string); + } - @Override - public void handleAttributeResource(V view, AttributeResource attribute) { - TypedArray a = attribute.apply(view.getContext()); - setString(view, a.getString(0)); - } + @Override + public void handleAttributeResource(V view, AttributeResource attribute) { + TypedArray a = attribute.apply(view.getContext()); + setString(view, a.getString(0)); + } - @Override - public void handleStyleResource(V view, StyleResource style) { - TypedArray a = style.apply(view.getContext()); - setString(view, a.getString(0)); - } + @Override + public void handleStyleResource(V view, StyleResource style) { + TypedArray a = style.apply(view.getContext()); + setString(view, a.getString(0)); + } - /** - * @param view View - */ - public abstract void setString(V view, String value); + /** + * @param view View + */ + public abstract void setString(V view, String value); - @Override - public Value compile(@Nullable Value value, Context context) { - if (null == value || value.isNull()) { - return ProteusConstants.EMPTY_STRING; - } - return value; + @Override + public Value compile(@Nullable Value value, Context context) { + if (null == value || value.isNull()) { + return ProteusConstants.EMPTY_STRING; } + return value; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/TweenAnimationResourceProcessor.java b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/TweenAnimationResourceProcessor.java index f467b96b..aa0902fa 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/processor/TweenAnimationResourceProcessor.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/processor/TweenAnimationResourceProcessor.java @@ -37,34 +37,34 @@ */ public abstract class TweenAnimationResourceProcessor extends AttributeProcessor { - private static final String TAG = "TweenAnimationResource"; + private static final String TAG = "TweenAnimationResource"; - @Override - public void handleValue(V view, Value value) { - Animation animation = AnimationUtils.loadAnimation(view.getContext(), value); - if (null != animation) { - setAnimation(view, animation); - } else { - if (ProteusConstants.isLoggingEnabled()) { - Log.e(TAG, "Animation Resource must be a primitive or an object. value -> " + value.toString()); - } - } + @Override + public void handleValue(V view, Value value) { + Animation animation = AnimationUtils.loadAnimation(view.getContext(), value); + if (null != animation) { + setAnimation(view, animation); + } else { + if (ProteusConstants.isLoggingEnabled()) { + Log.e(TAG, "Animation Resource must be a primitive or an object. value -> " + value.toString()); + } } + } - @Override - public void handleResource(V view, Resource resource) { + @Override + public void handleResource(V view, Resource resource) { - } + } - @Override - public void handleAttributeResource(V view, AttributeResource attribute) { + @Override + public void handleAttributeResource(V view, AttributeResource attribute) { - } + } - @Override - public void handleStyleResource(V view, StyleResource style) { + @Override + public void handleStyleResource(V view, StyleResource style) { - } + } - public abstract void setAnimation(V view, Animation animation); + public abstract void setAnimation(V view, Animation animation); } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/AnimationUtils.java b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/AnimationUtils.java index 4cdab4b8..72c22e32 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/AnimationUtils.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/AnimationUtils.java @@ -51,572 +51,572 @@ */ public class AnimationUtils { - private static final String TAG = "AnimationUtils"; - - private static final String LINEAR_INTERPOLATOR = "linearInterpolator"; - private static final String ACCELERATE_INTERPOLATOR = "accelerateInterpolator"; - private static final String DECELERATE_INTERPOLATOR = "decelerateInterpolator"; - private static final String ACCELERATE_DECELERATE_INTERPOLATOR = "accelerateDecelerateInterpolator"; - private static final String CYCLE_INTERPOLATOR = "cycleInterpolator"; - private static final String ANTICIPATE_INTERPOLATOR = "anticipateInterpolator"; - private static final String OVERSHOOT_INTERPOLATOR = "overshootInterpolator"; - private static final String ANTICIPATE_OVERSHOOT_INTERPOLATOR = "anticipateOvershootInterpolator"; - private static final String BOUNCE_INTERPOLATOR = "bounceInterpolator"; - private static final String PATH_INTERPOLATOR = "pathInterpolator"; - - - private static final String TYPE = "type"; - private static final String SET = "set"; - private static final String ALPHA = "alpha"; - private static final String SCALE = "scale"; - private static final String ROTATE = "rotate"; - private static final String TRANSLATE = "translate"; - - private static final String PERCENT_SELF = "%"; - private static final String PERCENT_RELATIVE_PARENT = "%p"; + private static final String TAG = "AnimationUtils"; + + private static final String LINEAR_INTERPOLATOR = "linearInterpolator"; + private static final String ACCELERATE_INTERPOLATOR = "accelerateInterpolator"; + private static final String DECELERATE_INTERPOLATOR = "decelerateInterpolator"; + private static final String ACCELERATE_DECELERATE_INTERPOLATOR = "accelerateDecelerateInterpolator"; + private static final String CYCLE_INTERPOLATOR = "cycleInterpolator"; + private static final String ANTICIPATE_INTERPOLATOR = "anticipateInterpolator"; + private static final String OVERSHOOT_INTERPOLATOR = "overshootInterpolator"; + private static final String ANTICIPATE_OVERSHOOT_INTERPOLATOR = "anticipateOvershootInterpolator"; + private static final String BOUNCE_INTERPOLATOR = "bounceInterpolator"; + private static final String PATH_INTERPOLATOR = "pathInterpolator"; + + + private static final String TYPE = "type"; + private static final String SET = "set"; + private static final String ALPHA = "alpha"; + private static final String SCALE = "scale"; + private static final String ROTATE = "rotate"; + private static final String TRANSLATE = "translate"; + + private static final String PERCENT_SELF = "%"; + private static final String PERCENT_RELATIVE_PARENT = "%p"; + + /** + * Loads an {@link Animation} object from a resource + * + * @param context Application context used to access resources + * @param value JSON representation of the Animation + * @return The animation object reference by the specified id + * @throws android.content.res.Resources.NotFoundException when the animation cannot be loaded + */ + public static Animation loadAnimation(Context context, Value value) throws Resources.NotFoundException { + Animation anim = null; + if (value.isPrimitive()) { + anim = handleString(context, value.getAsPrimitive().getAsString()); + } else if (value.isObject()) { + anim = handleElement(context, value.getAsObject()); + } else { + if (ProteusConstants.isLoggingEnabled()) { + Log.e(TAG, "Could not load animation for : " + value.toString()); + } + } + return anim; + } + + private static Animation handleString(Context c, String value) { + Animation anim = null; + if (ParseHelper.isTweenAnimationResource(value)) { + try { + Resources r = c.getResources(); + int animationId = r.getIdentifier(value, "anim", c.getPackageName()); + anim = android.view.animation.AnimationUtils.loadAnimation(c, animationId); + } catch (Exception ex) { + System.out.println("Could not load local resource " + value); + } + } + return anim; + } + + private static Animation handleElement(Context context, ObjectValue value) { + Animation anim = null; + String type = value.getAsString(TYPE); + AnimationProperties animationProperties = null; + if (SET.equalsIgnoreCase(type)) { + animationProperties = new AnimationSetProperties(value); + } else if (ALPHA.equalsIgnoreCase(type)) { + animationProperties = new AlphaAnimProperties(value); + } else if (SCALE.equalsIgnoreCase(type)) { + animationProperties = new ScaleAnimProperties(value); + } else if (ROTATE.equalsIgnoreCase(type)) { + animationProperties = new RotateAnimProperties(value); + } else if (TRANSLATE.equalsIgnoreCase(type)) { + animationProperties = new TranslateAnimProperties(value); + } - /** - * Loads an {@link Animation} object from a resource - * - * @param context Application context used to access resources - * @param value JSON representation of the Animation - * @return The animation object reference by the specified id - * @throws android.content.res.Resources.NotFoundException when the animation cannot be loaded - */ - public static Animation loadAnimation(Context context, Value value) throws Resources.NotFoundException { - Animation anim = null; - if (value.isPrimitive()) { - anim = handleString(context, value.getAsPrimitive().getAsString()); - } else if (value.isObject()) { - anim = handleElement(context, value.getAsObject()); - } else { - if (ProteusConstants.isLoggingEnabled()) { - Log.e(TAG, "Could not load animation for : " + value.toString()); - } - } - return anim; - } - - private static Animation handleString(Context c, String value) { - Animation anim = null; - if (ParseHelper.isTweenAnimationResource(value)) { - try { - Resources r = c.getResources(); - int animationId = r.getIdentifier(value, "anim", c.getPackageName()); - anim = android.view.animation.AnimationUtils.loadAnimation(c, animationId); - } catch (Exception ex) { - System.out.println("Could not load local resource " + value); - } - } - return anim; - } - - private static Animation handleElement(Context context, ObjectValue value) { - Animation anim = null; - String type = value.getAsString(TYPE); - AnimationProperties animationProperties = null; - if (SET.equalsIgnoreCase(type)) { - animationProperties = new AnimationSetProperties(value); - } else if (ALPHA.equalsIgnoreCase(type)) { - animationProperties = new AlphaAnimProperties(value); - } else if (SCALE.equalsIgnoreCase(type)) { - animationProperties = new ScaleAnimProperties(value); - } else if (ROTATE.equalsIgnoreCase(type)) { - animationProperties = new RotateAnimProperties(value); - } else if (TRANSLATE.equalsIgnoreCase(type)) { - animationProperties = new TranslateAnimProperties(value); - } + if (null != animationProperties) { + anim = animationProperties.instantiate(context); + } - if (null != animationProperties) { - anim = animationProperties.instantiate(context); - } + return anim; + } + + /** + * Loads an {@link Interpolator} object from a resource + * + * @param context Application context used to access resources + * @param value Json representation of the Interpolator + * @return The animation object reference by the specified id + * @throws android.content.res.Resources.NotFoundException + */ + public static Interpolator loadInterpolator(Context context, Value value) throws Resources.NotFoundException { + Interpolator interpolator = null; + if (value.isPrimitive()) { + interpolator = handleStringInterpolator(context, value.getAsString()); + } else if (value.isObject()) { + interpolator = handleElementInterpolator(context, value.getAsObject()); + } else { + if (ProteusConstants.isLoggingEnabled()) { + Log.e(TAG, "Could not load interpolator for : " + value.toString()); + } + } + return interpolator; + } + + private static Interpolator handleStringInterpolator(Context c, String value) { + Interpolator interpolator = null; + if (ParseHelper.isTweenAnimationResource(value)) { + try { + Resources r = c.getResources(); + int interpolatorID = r.getIdentifier(value, "anim", c.getPackageName()); + interpolator = android.view.animation.AnimationUtils.loadInterpolator(c, interpolatorID); + } catch (Exception ex) { + System.out.println("Could not load local resource " + value); + } + } + return interpolator; + } + + private static Interpolator handleElementInterpolator(Context c, ObjectValue value) { + + Interpolator interpolator = null; + String type = value.getAsString("type"); + InterpolatorProperties interpolatorProperties = null; + if (LINEAR_INTERPOLATOR.equalsIgnoreCase(type)) { + interpolator = new LinearInterpolator(); + } else if (ACCELERATE_INTERPOLATOR.equalsIgnoreCase(type)) { + interpolator = new AccelerateInterpolator(); + } else if (DECELERATE_INTERPOLATOR.equalsIgnoreCase(type)) { + interpolator = new DecelerateInterpolator(); + } else if (ACCELERATE_DECELERATE_INTERPOLATOR.equalsIgnoreCase(type)) { + interpolator = new AccelerateDecelerateInterpolator(); + } else if (CYCLE_INTERPOLATOR.equalsIgnoreCase(type)) { + interpolatorProperties = new CycleInterpolatorProperties(value); + } else if (ANTICIPATE_INTERPOLATOR.equalsIgnoreCase(type)) { + interpolatorProperties = new AnticipateInterpolatorProperties(value); + } else if (OVERSHOOT_INTERPOLATOR.equalsIgnoreCase(type)) { + interpolatorProperties = new OvershootInterpolatorProperties(value); + } else if (ANTICIPATE_OVERSHOOT_INTERPOLATOR.equalsIgnoreCase(type)) { + interpolatorProperties = new AnticipateOvershootInterpolatorProperties(value); + } else if (BOUNCE_INTERPOLATOR.equalsIgnoreCase(type)) { + interpolator = new BounceInterpolator(); + } else if (PATH_INTERPOLATOR.equalsIgnoreCase(type)) { + interpolatorProperties = new PathInterpolatorProperties(value); + } else { + if (ProteusConstants.isLoggingEnabled()) { + Log.e(TAG, "Unknown interpolator name: " + type); + } + throw new RuntimeException("Unknown interpolator name: " + type); + } - return anim; + if (null != interpolatorProperties) { + interpolator = interpolatorProperties.createInterpolator(c); } + return interpolator; + } + + /** + * Utility class to parse a string description of a size. + */ + private static class Description { + /** + * One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or + * Animation.RELATIVE_TO_PARENT. + */ + public int type; + /** - * Loads an {@link Interpolator} object from a resource + * The absolute or relative dimension for this Description. + */ + public float value; + + /** + * Size descriptions can appear in three forms: + *

    + *
  1. An absolute size. This is represented by a number.
  2. + *
  3. A size relative to the size of the object being animated. This + * is represented by a number followed by "%".
  4. * + *
  5. A size relative to the size of the parent of object being + * animated. This is represented by a number followed by "%p".
  6. + *
* - * @param context Application context used to access resources - * @param value Json representation of the Interpolator - * @return The animation object reference by the specified id - * @throws android.content.res.Resources.NotFoundException + * @param value The Json value to parse + * @return The parsed version of the description */ - public static Interpolator loadInterpolator(Context context, Value value) throws Resources.NotFoundException { - Interpolator interpolator = null; - if (value.isPrimitive()) { - interpolator = handleStringInterpolator(context, value.getAsString()); - } else if (value.isObject()) { - interpolator = handleElementInterpolator(context, value.getAsObject()); + static Description parseValue(Value value) { + Description d = new Description(); + d.type = Animation.ABSOLUTE; + d.value = 0; + if (value != null && value.isPrimitive()) { + if (value.getAsPrimitive().isNumber()) { + d.type = Animation.ABSOLUTE; + d.value = value.getAsPrimitive().getAsFloat(); } else { - if (ProteusConstants.isLoggingEnabled()) { - Log.e(TAG, "Could not load interpolator for : " + value.toString()); - } - } - return interpolator; - } - - private static Interpolator handleStringInterpolator(Context c, String value) { - Interpolator interpolator = null; - if (ParseHelper.isTweenAnimationResource(value)) { - try { - Resources r = c.getResources(); - int interpolatorID = r.getIdentifier(value, "anim", c.getPackageName()); - interpolator = android.view.animation.AnimationUtils.loadInterpolator(c, interpolatorID); - } catch (Exception ex) { - System.out.println("Could not load local resource " + value); - } - } - return interpolator; - } - - private static Interpolator handleElementInterpolator(Context c, ObjectValue value) { - - Interpolator interpolator = null; - String type = value.getAsString("type"); - InterpolatorProperties interpolatorProperties = null; - if (LINEAR_INTERPOLATOR.equalsIgnoreCase(type)) { - interpolator = new LinearInterpolator(); - } else if (ACCELERATE_INTERPOLATOR.equalsIgnoreCase(type)) { - interpolator = new AccelerateInterpolator(); - } else if (DECELERATE_INTERPOLATOR.equalsIgnoreCase(type)) { - interpolator = new DecelerateInterpolator(); - } else if (ACCELERATE_DECELERATE_INTERPOLATOR.equalsIgnoreCase(type)) { - interpolator = new AccelerateDecelerateInterpolator(); - } else if (CYCLE_INTERPOLATOR.equalsIgnoreCase(type)) { - interpolatorProperties = new CycleInterpolatorProperties(value); - } else if (ANTICIPATE_INTERPOLATOR.equalsIgnoreCase(type)) { - interpolatorProperties = new AnticipateInterpolatorProperties(value); - } else if (OVERSHOOT_INTERPOLATOR.equalsIgnoreCase(type)) { - interpolatorProperties = new OvershootInterpolatorProperties(value); - } else if (ANTICIPATE_OVERSHOOT_INTERPOLATOR.equalsIgnoreCase(type)) { - interpolatorProperties = new AnticipateOvershootInterpolatorProperties(value); - } else if (BOUNCE_INTERPOLATOR.equalsIgnoreCase(type)) { - interpolator = new BounceInterpolator(); - } else if (PATH_INTERPOLATOR.equalsIgnoreCase(type)) { - interpolatorProperties = new PathInterpolatorProperties(value); - } else { - if (ProteusConstants.isLoggingEnabled()) { - Log.e(TAG, "Unknown interpolator name: " + type); - } - throw new RuntimeException("Unknown interpolator name: " + type); - } - - if (null != interpolatorProperties) { - interpolator = interpolatorProperties.createInterpolator(c); + String stringValue = value.getAsPrimitive().getAsString(); + if (stringValue.endsWith(PERCENT_SELF)) { + stringValue = stringValue.substring(0, stringValue.length() - PERCENT_SELF.length()); + d.value = Float.parseFloat(stringValue) / 100; + d.type = Animation.RELATIVE_TO_SELF; + } else if (stringValue.endsWith(PERCENT_RELATIVE_PARENT)) { + stringValue = stringValue.substring(0, stringValue.length() - PERCENT_RELATIVE_PARENT.length()); + d.value = Float.parseFloat(stringValue) / 100; + d.type = Animation.RELATIVE_TO_PARENT; + } else { + d.type = Animation.ABSOLUTE; + d.value = value.getAsPrimitive().getAsFloat(); + } } + } - return interpolator; + return d; + } + } + + private abstract static class AnimationProperties { + + public static final String DETACH_WALLPAPER = "detachWallpaper"; + public static final String DURATION = "duration"; + public static final String FILL_AFTER = "fillAfter"; + public static final String FILL_BEFORE = "fillBefore"; + public static final String FILL_ENABLED = "fillEnabled"; + public static final String INTERPOLATOR = "interpolator"; + public static final String REPEAT_COUNT = "repeatCount"; + public static final String REPEAT_MODE = "repeatMode"; + public static final String START_OFFSET = "startOffset"; + public static final String Z_ADJUSTMENT = "zAdjustment"; + + Boolean detachWallpaper; + Long duration; + Boolean fillAfter; + Boolean fillBefore; + Boolean fillEnabled; + Value interpolator; + Integer repeatCount; + Integer repeatMode; + Long startOffset; + Integer zAdjustment; + + public AnimationProperties(ObjectValue value) { + detachWallpaper = value.getAsBoolean(DETACH_WALLPAPER); + duration = value.getAsLong(DURATION); + fillAfter = value.getAsBoolean(FILL_AFTER); + fillBefore = value.getAsBoolean(FILL_BEFORE); + fillEnabled = value.getAsBoolean(FILL_ENABLED); + interpolator = value.get(INTERPOLATOR); + repeatCount = value.getAsInteger(REPEAT_COUNT); + repeatMode = value.getAsInteger(REPEAT_MODE); + startOffset = value.getAsLong(START_OFFSET); + zAdjustment = value.getAsInteger(Z_ADJUSTMENT); } - /** - * Utility class to parse a string description of a size. - */ - private static class Description { - /** - * One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or - * Animation.RELATIVE_TO_PARENT. - */ - public int type; - - /** - * The absolute or relative dimension for this Description. - */ - public float value; - - /** - * Size descriptions can appear in three forms: - *
    - *
  1. An absolute size. This is represented by a number.
  2. - *
  3. A size relative to the size of the object being animated. This - * is represented by a number followed by "%".
  4. * - *
  5. A size relative to the size of the parent of object being - * animated. This is represented by a number followed by "%p".
  6. - *
- * - * @param value The Json value to parse - * @return The parsed version of the description - */ - static Description parseValue(Value value) { - Description d = new Description(); - d.type = Animation.ABSOLUTE; - d.value = 0; - if (value != null && value.isPrimitive()) { - if (value.getAsPrimitive().isNumber()) { - d.type = Animation.ABSOLUTE; - d.value = value.getAsPrimitive().getAsFloat(); - } else { - String stringValue = value.getAsPrimitive().getAsString(); - if (stringValue.endsWith(PERCENT_SELF)) { - stringValue = stringValue.substring(0, stringValue.length() - PERCENT_SELF.length()); - d.value = Float.parseFloat(stringValue) / 100; - d.type = Animation.RELATIVE_TO_SELF; - } else if (stringValue.endsWith(PERCENT_RELATIVE_PARENT)) { - stringValue = stringValue.substring(0, stringValue.length() - PERCENT_RELATIVE_PARENT.length()); - d.value = Float.parseFloat(stringValue) / 100; - d.type = Animation.RELATIVE_TO_PARENT; - } else { - d.type = Animation.ABSOLUTE; - d.value = value.getAsPrimitive().getAsFloat(); - } - } - } + public Animation instantiate(Context c) { + Animation anim = createAnimation(c); + if (null != anim) { + if (null != detachWallpaper) { + anim.setDetachWallpaper(detachWallpaper); + } - return d; + if (null != duration) { + anim.setDuration(duration); } - } - private abstract static class AnimationProperties { - - public static final String DETACH_WALLPAPER = "detachWallpaper"; - public static final String DURATION = "duration"; - public static final String FILL_AFTER = "fillAfter"; - public static final String FILL_BEFORE = "fillBefore"; - public static final String FILL_ENABLED = "fillEnabled"; - public static final String INTERPOLATOR = "interpolator"; - public static final String REPEAT_COUNT = "repeatCount"; - public static final String REPEAT_MODE = "repeatMode"; - public static final String START_OFFSET = "startOffset"; - public static final String Z_ADJUSTMENT = "zAdjustment"; - - Boolean detachWallpaper; - Long duration; - Boolean fillAfter; - Boolean fillBefore; - Boolean fillEnabled; - Value interpolator; - Integer repeatCount; - Integer repeatMode; - Long startOffset; - Integer zAdjustment; - - public AnimationProperties(ObjectValue value) { - detachWallpaper = value.getAsBoolean(DETACH_WALLPAPER); - duration = value.getAsLong(DURATION); - fillAfter = value.getAsBoolean(FILL_AFTER); - fillBefore = value.getAsBoolean(FILL_BEFORE); - fillEnabled = value.getAsBoolean(FILL_ENABLED); - interpolator = value.get(INTERPOLATOR); - repeatCount = value.getAsInteger(REPEAT_COUNT); - repeatMode = value.getAsInteger(REPEAT_MODE); - startOffset = value.getAsLong(START_OFFSET); - zAdjustment = value.getAsInteger(Z_ADJUSTMENT); + if (null != fillAfter) { + anim.setFillAfter(fillAfter); } - public Animation instantiate(Context c) { - Animation anim = createAnimation(c); - if (null != anim) { - if (null != detachWallpaper) { - anim.setDetachWallpaper(detachWallpaper); - } - - if (null != duration) { - anim.setDuration(duration); - } - - if (null != fillAfter) { - anim.setFillAfter(fillAfter); - } - - if (null != fillBefore) { - anim.setFillBefore(fillBefore); - } - - if (null != fillEnabled) { - anim.setFillEnabled(fillEnabled); - } - - if (null != interpolator) { - Interpolator i = loadInterpolator(c, interpolator); - if (null != i) { - anim.setInterpolator(i); - } - } - - if (null != repeatCount) { - anim.setRepeatCount(repeatCount); - } - - if (null != repeatMode) { - anim.setRepeatMode(repeatMode); - } - - if (null != startOffset) { - anim.setStartOffset(startOffset); - } - - if (null != zAdjustment) { - anim.setZAdjustment(zAdjustment); - } - } - return anim; + if (null != fillBefore) { + anim.setFillBefore(fillBefore); } - abstract Animation createAnimation(Context c); - } + if (null != fillEnabled) { + anim.setFillEnabled(fillEnabled); + } - private static class AnimationSetProperties extends AnimationProperties { + if (null != interpolator) { + Interpolator i = loadInterpolator(c, interpolator); + if (null != i) { + anim.setInterpolator(i); + } + } - public static final String SHARE_INTERPOLATOR = "shareInterpolator"; - public static final String CHILDREN = "children"; + if (null != repeatCount) { + anim.setRepeatCount(repeatCount); + } - Boolean shareInterpolator; - Value children; + if (null != repeatMode) { + anim.setRepeatMode(repeatMode); + } - public AnimationSetProperties(ObjectValue value) { - super(value); - shareInterpolator = value.getAsBoolean(SHARE_INTERPOLATOR); - children = value.get(CHILDREN); + if (null != startOffset) { + anim.setStartOffset(startOffset); } - @Override - Animation createAnimation(Context c) { - AnimationSet animationSet = new AnimationSet(shareInterpolator == null ? true : shareInterpolator); - - if (null != children) { - if (children.isArray()) { - Iterator iterator = children.getAsArray().iterator(); - while (iterator.hasNext()) { - Animation animation = loadAnimation(c, iterator.next()); - if (null != animation) { - animationSet.addAnimation(animation); - } - } - } else if (children.isObject() || children.isPrimitive()) { - Animation animation = loadAnimation(c, children); - if (null != animation) { - animationSet.addAnimation(animation); - } - } - } - return animationSet; + if (null != zAdjustment) { + anim.setZAdjustment(zAdjustment); } + } + return anim; } - private static class AlphaAnimProperties extends AnimationProperties { + abstract Animation createAnimation(Context c); + } - public static final String FROM_ALPHA = "fromAlpha"; - public static final String TO_ALPHA = "toAlpha"; + private static class AnimationSetProperties extends AnimationProperties { - public Float fromAlpha; - public Float toAlpha; + public static final String SHARE_INTERPOLATOR = "shareInterpolator"; + public static final String CHILDREN = "children"; - public AlphaAnimProperties(ObjectValue value) { - super(value); - fromAlpha = value.getAsFloat(FROM_ALPHA); - toAlpha = value.getAsFloat(TO_ALPHA); - } + Boolean shareInterpolator; + Value children; - @Override - Animation createAnimation(Context c) { - return null == fromAlpha || null == toAlpha ? null : new AlphaAnimation(fromAlpha, toAlpha); - } + public AnimationSetProperties(ObjectValue value) { + super(value); + shareInterpolator = value.getAsBoolean(SHARE_INTERPOLATOR); + children = value.get(CHILDREN); } - private static class ScaleAnimProperties extends AnimationProperties { - - public static final String FROM_X_SCALE = "fromXScale"; - public static final String TO_X_SCALE = "toXScale"; - public static final String FROM_Y_SCALE = "fromYScale"; - public static final String TO_Y_SCALE = "toYScale"; - public static final String PIVOT_X = "pivotX"; - public static final String PIVOT_Y = "pivotY"; - - public Float fromXScale; - public Float toXScale; - public Float fromYScale; - public Float toYScale; - public Value pivotX; - public Value pivotY; - - public ScaleAnimProperties(ObjectValue value) { - super(value); - fromXScale = value.getAsFloat(FROM_X_SCALE); - toXScale = value.getAsFloat(TO_X_SCALE); - fromYScale = value.getAsFloat(FROM_Y_SCALE); - toYScale = value.getAsFloat(TO_Y_SCALE); - pivotX = value.get(PIVOT_X); - pivotY = value.get(PIVOT_Y); - } - - @Override - Animation createAnimation(Context c) { - if (pivotX != null && pivotY != null) { - Description pivotXDesc = Description.parseValue(pivotX); - Description pivotYDesc = Description.parseValue(pivotY); - return new ScaleAnimation(fromXScale, toXScale, fromYScale, toYScale, pivotXDesc.type, pivotXDesc.value, pivotYDesc.type, pivotYDesc.value); - } else { - return new ScaleAnimation(fromXScale, toXScale, fromYScale, toYScale); + @Override + Animation createAnimation(Context c) { + AnimationSet animationSet = new AnimationSet(shareInterpolator == null ? true : shareInterpolator); + + if (null != children) { + if (children.isArray()) { + Iterator iterator = children.getAsArray().iterator(); + while (iterator.hasNext()) { + Animation animation = loadAnimation(c, iterator.next()); + if (null != animation) { + animationSet.addAnimation(animation); } - } + } + } else if (children.isObject() || children.isPrimitive()) { + Animation animation = loadAnimation(c, children); + if (null != animation) { + animationSet.addAnimation(animation); + } + } + } + return animationSet; } + } - private static class TranslateAnimProperties extends AnimationProperties { + private static class AlphaAnimProperties extends AnimationProperties { - public static final String FROM_X_DELTA = "fromXDelta"; - public static final String TO_X_DELTA = "toXDelta"; - public static final String FROM_Y_DELTA = "fromYDelta"; - public static final String TO_Y_DELTA = "toYDelta"; + public static final String FROM_ALPHA = "fromAlpha"; + public static final String TO_ALPHA = "toAlpha"; - public Value fromXDelta; - public Value toXDelta; - public Value fromYDelta; - public Value toYDelta; + public Float fromAlpha; + public Float toAlpha; - public TranslateAnimProperties(ObjectValue value) { - super(value); - fromXDelta = value.get(FROM_X_DELTA); - toXDelta = value.get(TO_X_DELTA); - fromXDelta = value.get(FROM_Y_DELTA); - toYDelta = value.get(TO_Y_DELTA); - } - - @Override - Animation createAnimation(Context c) { - Description fromXDeltaDescription = Description.parseValue(fromXDelta); - Description toXDeltaDescription = Description.parseValue(toXDelta); - Description fromYDeltaDescription = Description.parseValue(fromYDelta); - Description toYDeltaDescription = Description.parseValue(toYDelta); - - return new TranslateAnimation(fromXDeltaDescription.type, fromXDeltaDescription.value, toXDeltaDescription.type, toXDeltaDescription.value, fromYDeltaDescription.type, fromYDeltaDescription.value, toYDeltaDescription.type, toYDeltaDescription.value); - } + public AlphaAnimProperties(ObjectValue value) { + super(value); + fromAlpha = value.getAsFloat(FROM_ALPHA); + toAlpha = value.getAsFloat(TO_ALPHA); } - private static class RotateAnimProperties extends AnimationProperties { + @Override + Animation createAnimation(Context c) { + return null == fromAlpha || null == toAlpha ? null : new AlphaAnimation(fromAlpha, toAlpha); + } + } + + private static class ScaleAnimProperties extends AnimationProperties { + + public static final String FROM_X_SCALE = "fromXScale"; + public static final String TO_X_SCALE = "toXScale"; + public static final String FROM_Y_SCALE = "fromYScale"; + public static final String TO_Y_SCALE = "toYScale"; + public static final String PIVOT_X = "pivotX"; + public static final String PIVOT_Y = "pivotY"; + + public Float fromXScale; + public Float toXScale; + public Float fromYScale; + public Float toYScale; + public Value pivotX; + public Value pivotY; + + public ScaleAnimProperties(ObjectValue value) { + super(value); + fromXScale = value.getAsFloat(FROM_X_SCALE); + toXScale = value.getAsFloat(TO_X_SCALE); + fromYScale = value.getAsFloat(FROM_Y_SCALE); + toYScale = value.getAsFloat(TO_Y_SCALE); + pivotX = value.get(PIVOT_X); + pivotY = value.get(PIVOT_Y); + } - public static final String FROM_DEGREES = "fromDegrees"; - public static final String TO_DEGREES = "toDegrees"; - public static final String PIVOT_X = "pivotX"; - public static final String PIVOT_Y = "pivotY"; + @Override + Animation createAnimation(Context c) { + if (pivotX != null && pivotY != null) { + Description pivotXDesc = Description.parseValue(pivotX); + Description pivotYDesc = Description.parseValue(pivotY); + return new ScaleAnimation(fromXScale, toXScale, fromYScale, toYScale, pivotXDesc.type, pivotXDesc.value, pivotYDesc.type, pivotYDesc.value); + } else { + return new ScaleAnimation(fromXScale, toXScale, fromYScale, toYScale); + } + } + } + + private static class TranslateAnimProperties extends AnimationProperties { + + public static final String FROM_X_DELTA = "fromXDelta"; + public static final String TO_X_DELTA = "toXDelta"; + public static final String FROM_Y_DELTA = "fromYDelta"; + public static final String TO_Y_DELTA = "toYDelta"; + + public Value fromXDelta; + public Value toXDelta; + public Value fromYDelta; + public Value toYDelta; + + public TranslateAnimProperties(ObjectValue value) { + super(value); + fromXDelta = value.get(FROM_X_DELTA); + toXDelta = value.get(TO_X_DELTA); + fromXDelta = value.get(FROM_Y_DELTA); + toYDelta = value.get(TO_Y_DELTA); + } - public Float fromDegrees; - public Float toDegrees; - public Value pivotX; - public Value pivotY; + @Override + Animation createAnimation(Context c) { + Description fromXDeltaDescription = Description.parseValue(fromXDelta); + Description toXDeltaDescription = Description.parseValue(toXDelta); + Description fromYDeltaDescription = Description.parseValue(fromYDelta); + Description toYDeltaDescription = Description.parseValue(toYDelta); - public RotateAnimProperties(ObjectValue value) { - super(value); - fromDegrees = value.getAsFloat(FROM_DEGREES); - toDegrees = value.getAsFloat(TO_DEGREES); - pivotX = value.get(PIVOT_X); - pivotY = value.get(PIVOT_Y); - } + return new TranslateAnimation(fromXDeltaDescription.type, fromXDeltaDescription.value, toXDeltaDescription.type, toXDeltaDescription.value, fromYDeltaDescription.type, fromYDeltaDescription.value, toYDeltaDescription.type, toYDeltaDescription.value); + } + } + + private static class RotateAnimProperties extends AnimationProperties { + + public static final String FROM_DEGREES = "fromDegrees"; + public static final String TO_DEGREES = "toDegrees"; + public static final String PIVOT_X = "pivotX"; + public static final String PIVOT_Y = "pivotY"; + + public Float fromDegrees; + public Float toDegrees; + public Value pivotX; + public Value pivotY; + + public RotateAnimProperties(ObjectValue value) { + super(value); + fromDegrees = value.getAsFloat(FROM_DEGREES); + toDegrees = value.getAsFloat(TO_DEGREES); + pivotX = value.get(PIVOT_X); + pivotY = value.get(PIVOT_Y); + } - @Override - Animation createAnimation(Context c) { - if (null != pivotX && null != pivotY) { - Description pivotXDesc = Description.parseValue(pivotX); - Description pivotYDesc = Description.parseValue(pivotY); - return new RotateAnimation(fromDegrees, toDegrees, pivotXDesc.type, pivotXDesc.value, pivotYDesc.type, pivotYDesc.value); - } else { - return new RotateAnimation(fromDegrees, toDegrees); - } - } + @Override + Animation createAnimation(Context c) { + if (null != pivotX && null != pivotY) { + Description pivotXDesc = Description.parseValue(pivotX); + Description pivotYDesc = Description.parseValue(pivotY); + return new RotateAnimation(fromDegrees, toDegrees, pivotXDesc.type, pivotXDesc.value, pivotYDesc.type, pivotYDesc.value); + } else { + return new RotateAnimation(fromDegrees, toDegrees); + } } + } - private abstract static class InterpolatorProperties { + private abstract static class InterpolatorProperties { - public InterpolatorProperties(Value value) { - } + public InterpolatorProperties(Value value) { + } - abstract Interpolator createInterpolator(Context c); + abstract Interpolator createInterpolator(Context c); - } + } - private static class PathInterpolatorProperties extends InterpolatorProperties { + private static class PathInterpolatorProperties extends InterpolatorProperties { - public static final String CONTROL_X1 = "controlX1"; - public static final String CONTROL_Y1 = "controlY1"; - public static final String CONTROL_X2 = "controlX2"; - public static final String CONTROL_Y2 = "controlY2"; + public static final String CONTROL_X1 = "controlX1"; + public static final String CONTROL_Y1 = "controlY1"; + public static final String CONTROL_X2 = "controlX2"; + public static final String CONTROL_Y2 = "controlY2"; - public Float controlX1; - public Float controlY1; - public Float controlX2; - public Float controlY2; + public Float controlX1; + public Float controlY1; + public Float controlX2; + public Float controlY2; - public PathInterpolatorProperties(ObjectValue parser) { - super(parser); - controlX1 = parser.getAsFloat(CONTROL_X1); - controlY1 = parser.getAsFloat(CONTROL_Y1); - controlX2 = parser.getAsFloat(CONTROL_X2); - controlY2 = parser.getAsFloat(CONTROL_Y2); - } + public PathInterpolatorProperties(ObjectValue parser) { + super(parser); + controlX1 = parser.getAsFloat(CONTROL_X1); + controlY1 = parser.getAsFloat(CONTROL_Y1); + controlX2 = parser.getAsFloat(CONTROL_X2); + controlY2 = parser.getAsFloat(CONTROL_Y2); + } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - Interpolator createInterpolator(Context c) { - if (null != controlX2 && null != controlY2) { - return new PathInterpolator(controlX1, controlY1, controlX2, controlY2); - } else { - return new PathInterpolator(controlX1, controlY1); - } - } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + Interpolator createInterpolator(Context c) { + if (null != controlX2 && null != controlY2) { + return new PathInterpolator(controlX1, controlY1, controlX2, controlY2); + } else { + return new PathInterpolator(controlX1, controlY1); + } } + } - private static class AnticipateInterpolatorProperties extends InterpolatorProperties { + private static class AnticipateInterpolatorProperties extends InterpolatorProperties { - public static final String TENSION = "tension"; + public static final String TENSION = "tension"; - public Float tension; + public Float tension; - public AnticipateInterpolatorProperties(ObjectValue parser) { - super(parser); - tension = parser.getAsFloat(TENSION); - } + public AnticipateInterpolatorProperties(ObjectValue parser) { + super(parser); + tension = parser.getAsFloat(TENSION); + } - Interpolator createInterpolator(Context c) { - return new AnticipateInterpolator(tension); - } + Interpolator createInterpolator(Context c) { + return new AnticipateInterpolator(tension); } + } - private static class OvershootInterpolatorProperties extends InterpolatorProperties { + private static class OvershootInterpolatorProperties extends InterpolatorProperties { - public static final String TENSION = "tension"; + public static final String TENSION = "tension"; - public Float tension; + public Float tension; - public OvershootInterpolatorProperties(ObjectValue parser) { - super(parser); - tension = parser.getAsFloat(TENSION); - } + public OvershootInterpolatorProperties(ObjectValue parser) { + super(parser); + tension = parser.getAsFloat(TENSION); + } - Interpolator createInterpolator(Context c) { - return tension == null ? new OvershootInterpolator() : new OvershootInterpolator(tension); - } + Interpolator createInterpolator(Context c) { + return tension == null ? new OvershootInterpolator() : new OvershootInterpolator(tension); } + } - private static class AnticipateOvershootInterpolatorProperties extends InterpolatorProperties { + private static class AnticipateOvershootInterpolatorProperties extends InterpolatorProperties { - public static final String TENSION = "tension"; - public static final String EXTRA_TENSION = "extraTension"; + public static final String TENSION = "tension"; + public static final String EXTRA_TENSION = "extraTension"; - public Float tension; - public Float extraTension; + public Float tension; + public Float extraTension; - public AnticipateOvershootInterpolatorProperties(ObjectValue parser) { - super(parser); - tension = parser.getAsFloat(TENSION); - extraTension = parser.getAsFloat(EXTRA_TENSION); - } + public AnticipateOvershootInterpolatorProperties(ObjectValue parser) { + super(parser); + tension = parser.getAsFloat(TENSION); + extraTension = parser.getAsFloat(EXTRA_TENSION); + } - Interpolator createInterpolator(Context c) { - return null == tension ? new AnticipateOvershootInterpolator() : (null == extraTension ? new AnticipateOvershootInterpolator(tension) : new AnticipateOvershootInterpolator(tension, extraTension)); - } + Interpolator createInterpolator(Context c) { + return null == tension ? new AnticipateOvershootInterpolator() : (null == extraTension ? new AnticipateOvershootInterpolator(tension) : new AnticipateOvershootInterpolator(tension, extraTension)); } + } - private static class CycleInterpolatorProperties extends InterpolatorProperties { + private static class CycleInterpolatorProperties extends InterpolatorProperties { - public static final String CYCLES = "cycles"; + public static final String CYCLES = "cycles"; - public Float cycles; + public Float cycles; - public CycleInterpolatorProperties(ObjectValue parser) { - super(parser); - cycles = parser.getAsFloat(CYCLES); - } + public CycleInterpolatorProperties(ObjectValue parser) { + super(parser); + cycles = parser.getAsFloat(CYCLES); + } - Interpolator createInterpolator(Context c) { - return new CycleInterpolator(cycles); - } + Interpolator createInterpolator(Context c) { + return new CycleInterpolator(cycles); } + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Attributes.java b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Attributes.java index aebadc7a..286628bc 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Attributes.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Attributes.java @@ -22,197 +22,197 @@ */ public class Attributes { - public static class View { - public static final String Above = "layout_above"; - public static final String Activated = "activated"; - public static final String AlignBaseline = "layout_alignBaseline"; - public static final String AlignBottom = "layout_alignBottom"; - public static final String AlignEnd = "layout_alignEnd"; - public static final String AlignLeft = "layout_alignLeft"; - public static final String AlignParentBottom = "layout_alignParentBottom"; - public static final String AlignParentEnd = "layout_alignParentEnd"; - public static final String AlignParentLeft = "layout_alignParentLeft"; - public static final String AlignParentRight = "layout_alignParentRight"; - public static final String AlignParentStart = "layout_alignParentStart"; - public static final String AlignParentTop = "layout_alignParentTop"; - public static final String AlignRight = "layout_alignRight"; - public static final String AlignStart = "layout_alignStart"; - public static final String AlignTop = "layout_alignTop"; - public static final String Alpha = "alpha"; - public static final String Animation = "animation"; - public static final String Background = "background"; - public static final String BackgroundTint = "backgroundTint"; - public static final String BackgroundTintMode = "backgroundTintMode"; - public static final String Below = "layout_below"; - public static final String CenterHorizontal = "layout_centerHorizontal"; - public static final String CenterInParent = "layout_centerInParent"; - public static final String CenterVertical = "layout_centerVertical"; - public static final String Clickable = "clickable"; - public static final String ContentDescription = "contentDescription"; - public static final String ContextClickable = "contextClickable"; - public static final String DrawingCacheQuality = "drawingCacheQuality"; - public static final String Elevation = "elevation"; - public static final String Enabled = "enabled"; - public static final String FadeScrollbars = "fadeScrollbars"; - public static final String FadingEdgeLength = "fadingEdgeLength"; - public static final String FilterTouchesWhenObscured = "filterTouchesWhenObscured"; - public static final String FitsSystemWindows = "fitsSystemWindows"; - public static final String Focusable = "focusable"; - public static final String FocusableInTouchMode = "focusableInTouchMode"; - public static final String ForceHasOverlappingRendering = "forceHasOverlappingRendering"; - public static final String Foreground = "foreground"; - public static final String ForegroundGravity = "foregroundGravity"; - public static final String ForegroundTint = "foregroundTint"; - public static final String ForegroundTintMode = "foregroundTintMode"; - public static final String Gravity = "gravity"; - public static final String HapticFeedbackEnabled = "hapticFeedbackEnabled"; - public static final String Height = "layout_height"; - public static final String Id = "id"; - public static final String IsScrollContainer = "isScrollContainer"; - public static final String KeepScreenOn = "keepScreenOn"; - public static final String LayerType = "layerType"; - public static final String LayoutDirection = "layoutDirection"; - public static final String LayoutGravity = "layout_gravity"; - public static final String LongClickable = "longClickable"; - public static final String Margin = "layout_margin"; - public static final String MarginBottom = "layout_marginBottom"; - public static final String MarginLeft = "layout_marginLeft"; - public static final String MarginRight = "layout_marginRight"; - public static final String MarginTop = "layout_marginTop"; - public static final String MinHeight = "minHeight"; - public static final String MinWidth = "minWidth"; - public static final String NextFocusDown = "nextFocusDown"; - public static final String NextFocusForward = "nextFocusForward"; - public static final String NextFocusLeft = "nextFocusLeft"; - public static final String NextFocusRight = "nextFocusRight"; - public static final String NextFocusUp = "nextFocusUp"; - public static final String OnClick = "onClick"; - public static final String OnLongClick = "onLongClick"; - public static final String OnTouch = "onTouch"; - public static final String Padding = "padding"; - public static final String PaddingBottom = "paddingBottom"; - public static final String PaddingEnd = "paddingEnd"; - public static final String PaddingLeft = "paddingLeft"; - public static final String PaddingRight = "paddingRight"; - public static final String PaddingStart = "paddingStart"; - public static final String PaddingTop = "paddingTop"; - public static final String RequiresFadingEdge = "requiresFadingEdge"; - public static final String Rotation = "rotation"; - public static final String RotationX = "rotationX"; - public static final String RotationY = "rotationY"; - public static final String SaveEnabled = "saveEnabled"; - public static final String ScaleX = "scaleX"; - public static final String ScaleY = "scaleY"; - public static final String ScrollIndicators = "scrollIndicators"; - public static final String ScrollbarDefaultDelayBeforeFade = "scrollbarDefaultDelayBeforeFade"; - public static final String ScrollbarFadeDuration = "scrollbarFadeDuration"; - public static final String ScrollbarSize = "scrollbarSize"; - public static final String ScrollbarStyle = "scrollbarStyle"; - public static final String Selected = "selected"; - public static final String SoundEffectsEnabled = "soundEffectsEnabled"; - public static final String Style = "style"; - public static final String Tag = "tag"; - public static final String TextAlignment = "textAlignment"; - public static final String TextDirection = "textDirection"; - public static final String ToEndOf = "layout_toEndOf"; - public static final String ToLeftOf = "layout_toLeftOf"; - public static final String ToRightOf = "layout_toRightOf"; - public static final String ToStartOf = "layout_toStartOf"; - public static final String TransformPivotX = "transformPivotX"; - public static final String TransformPivotY = "transformPivotY"; - public static final String TransitionName = "transitionName"; - public static final String TranslationX = "translationX"; - public static final String TranslationY = "translationY"; - public static final String TranslationZ = "translationZ"; - public static final String Visibility = "visibility"; - public static final String Weight = "layout_weight"; - public static final String Width = "layout_width"; - } + public static class View { + public static final String Above = "layout_above"; + public static final String Activated = "activated"; + public static final String AlignBaseline = "layout_alignBaseline"; + public static final String AlignBottom = "layout_alignBottom"; + public static final String AlignEnd = "layout_alignEnd"; + public static final String AlignLeft = "layout_alignLeft"; + public static final String AlignParentBottom = "layout_alignParentBottom"; + public static final String AlignParentEnd = "layout_alignParentEnd"; + public static final String AlignParentLeft = "layout_alignParentLeft"; + public static final String AlignParentRight = "layout_alignParentRight"; + public static final String AlignParentStart = "layout_alignParentStart"; + public static final String AlignParentTop = "layout_alignParentTop"; + public static final String AlignRight = "layout_alignRight"; + public static final String AlignStart = "layout_alignStart"; + public static final String AlignTop = "layout_alignTop"; + public static final String Alpha = "alpha"; + public static final String Animation = "animation"; + public static final String Background = "background"; + public static final String BackgroundTint = "backgroundTint"; + public static final String BackgroundTintMode = "backgroundTintMode"; + public static final String Below = "layout_below"; + public static final String CenterHorizontal = "layout_centerHorizontal"; + public static final String CenterInParent = "layout_centerInParent"; + public static final String CenterVertical = "layout_centerVertical"; + public static final String Clickable = "clickable"; + public static final String ContentDescription = "contentDescription"; + public static final String ContextClickable = "contextClickable"; + public static final String DrawingCacheQuality = "drawingCacheQuality"; + public static final String Elevation = "elevation"; + public static final String Enabled = "enabled"; + public static final String FadeScrollbars = "fadeScrollbars"; + public static final String FadingEdgeLength = "fadingEdgeLength"; + public static final String FilterTouchesWhenObscured = "filterTouchesWhenObscured"; + public static final String FitsSystemWindows = "fitsSystemWindows"; + public static final String Focusable = "focusable"; + public static final String FocusableInTouchMode = "focusableInTouchMode"; + public static final String ForceHasOverlappingRendering = "forceHasOverlappingRendering"; + public static final String Foreground = "foreground"; + public static final String ForegroundGravity = "foregroundGravity"; + public static final String ForegroundTint = "foregroundTint"; + public static final String ForegroundTintMode = "foregroundTintMode"; + public static final String Gravity = "gravity"; + public static final String HapticFeedbackEnabled = "hapticFeedbackEnabled"; + public static final String Height = "layout_height"; + public static final String Id = "id"; + public static final String IsScrollContainer = "isScrollContainer"; + public static final String KeepScreenOn = "keepScreenOn"; + public static final String LayerType = "layerType"; + public static final String LayoutDirection = "layoutDirection"; + public static final String LayoutGravity = "layout_gravity"; + public static final String LongClickable = "longClickable"; + public static final String Margin = "layout_margin"; + public static final String MarginBottom = "layout_marginBottom"; + public static final String MarginLeft = "layout_marginLeft"; + public static final String MarginRight = "layout_marginRight"; + public static final String MarginTop = "layout_marginTop"; + public static final String MinHeight = "minHeight"; + public static final String MinWidth = "minWidth"; + public static final String NextFocusDown = "nextFocusDown"; + public static final String NextFocusForward = "nextFocusForward"; + public static final String NextFocusLeft = "nextFocusLeft"; + public static final String NextFocusRight = "nextFocusRight"; + public static final String NextFocusUp = "nextFocusUp"; + public static final String OnClick = "onClick"; + public static final String OnLongClick = "onLongClick"; + public static final String OnTouch = "onTouch"; + public static final String Padding = "padding"; + public static final String PaddingBottom = "paddingBottom"; + public static final String PaddingEnd = "paddingEnd"; + public static final String PaddingLeft = "paddingLeft"; + public static final String PaddingRight = "paddingRight"; + public static final String PaddingStart = "paddingStart"; + public static final String PaddingTop = "paddingTop"; + public static final String RequiresFadingEdge = "requiresFadingEdge"; + public static final String Rotation = "rotation"; + public static final String RotationX = "rotationX"; + public static final String RotationY = "rotationY"; + public static final String SaveEnabled = "saveEnabled"; + public static final String ScaleX = "scaleX"; + public static final String ScaleY = "scaleY"; + public static final String ScrollIndicators = "scrollIndicators"; + public static final String ScrollbarDefaultDelayBeforeFade = "scrollbarDefaultDelayBeforeFade"; + public static final String ScrollbarFadeDuration = "scrollbarFadeDuration"; + public static final String ScrollbarSize = "scrollbarSize"; + public static final String ScrollbarStyle = "scrollbarStyle"; + public static final String Selected = "selected"; + public static final String SoundEffectsEnabled = "soundEffectsEnabled"; + public static final String Style = "style"; + public static final String Tag = "tag"; + public static final String TextAlignment = "textAlignment"; + public static final String TextDirection = "textDirection"; + public static final String ToEndOf = "layout_toEndOf"; + public static final String ToLeftOf = "layout_toLeftOf"; + public static final String ToRightOf = "layout_toRightOf"; + public static final String ToStartOf = "layout_toStartOf"; + public static final String TransformPivotX = "transformPivotX"; + public static final String TransformPivotY = "transformPivotY"; + public static final String TransitionName = "transitionName"; + public static final String TranslationX = "translationX"; + public static final String TranslationY = "translationY"; + public static final String TranslationZ = "translationZ"; + public static final String Visibility = "visibility"; + public static final String Weight = "layout_weight"; + public static final String Width = "layout_width"; + } - public static class WebView { - public static final String Url = "url"; - public static final String HTML = "html"; - } + public static class WebView { + public static final String Url = "url"; + public static final String HTML = "html"; + } - public static class RatingBar { - public static final String NumStars = "numStars"; - public static final String Rating = "rating"; - public static final String IsIndicator = "isIndicator"; - public static final String StepSize = "stepSize"; - public static final String ProgressDrawable = "progressDrawable"; - public static final String MinHeight = "minHeight"; - } + public static class RatingBar { + public static final String NumStars = "numStars"; + public static final String Rating = "rating"; + public static final String IsIndicator = "isIndicator"; + public static final String StepSize = "stepSize"; + public static final String ProgressDrawable = "progressDrawable"; + public static final String MinHeight = "minHeight"; + } - public static class TextView { - public static final String Gravity = "gravity"; - public static final String Text = "text"; - public static final String HTML = "html"; - public static final String TextSize = "textSize"; - public static final String TextColor = "textColor"; - public static final String TextColorHint = "textColorHint"; - public static final String TextColorLink = "textColorLink"; - public static final String TextColorHighLight = "textColorHighlight"; - public static final String DrawableLeft = "drawableLeft"; - public static final String DrawableRight = "drawableRight"; - public static final String DrawableTop = "drawableTop"; - public static final String DrawableBottom = "drawableBottom"; - public static final String DrawablePadding = "drawablePadding"; - public static final String MaxLines = "maxLines"; - public static final String Ellipsize = "ellipsize"; - public static final String PaintFlags = "paintFlags"; - public static final String Prefix = "prefix"; - public static final String Suffix = "suffix"; - public static final String TextStyle = "textStyle"; - public static final String SingleLine = "singleLine"; - public static final String TextAllCaps = "textAllCaps"; - public static final String Hint = "hint"; - } + public static class TextView { + public static final String Gravity = "gravity"; + public static final String Text = "text"; + public static final String HTML = "html"; + public static final String TextSize = "textSize"; + public static final String TextColor = "textColor"; + public static final String TextColorHint = "textColorHint"; + public static final String TextColorLink = "textColorLink"; + public static final String TextColorHighLight = "textColorHighlight"; + public static final String DrawableLeft = "drawableLeft"; + public static final String DrawableRight = "drawableRight"; + public static final String DrawableTop = "drawableTop"; + public static final String DrawableBottom = "drawableBottom"; + public static final String DrawablePadding = "drawablePadding"; + public static final String MaxLines = "maxLines"; + public static final String Ellipsize = "ellipsize"; + public static final String PaintFlags = "paintFlags"; + public static final String Prefix = "prefix"; + public static final String Suffix = "suffix"; + public static final String TextStyle = "textStyle"; + public static final String SingleLine = "singleLine"; + public static final String TextAllCaps = "textAllCaps"; + public static final String Hint = "hint"; + } - public static class CheckBox { - public static final String Checked = "checked"; - public static final String Button = "button"; - } + public static class CheckBox { + public static final String Checked = "checked"; + public static final String Button = "button"; + } - public static class FrameLayout { - public static final String HeightRatio = "heightRatio"; - public static final String WidthRatio = "widthRatio"; - } + public static class FrameLayout { + public static final String HeightRatio = "heightRatio"; + public static final String WidthRatio = "widthRatio"; + } - public static class ImageView { - public static final String Src = "src"; - public static final String ScaleType = "scaleType"; - public static final String AdjustViewBounds = "adjustViewBounds"; - } + public static class ImageView { + public static final String Src = "src"; + public static final String ScaleType = "scaleType"; + public static final String AdjustViewBounds = "adjustViewBounds"; + } - public static class ViewGroup { - public static final String Children = "children"; - public static final String ClipChildren = "clipChildren"; - public static final String ClipToPadding = "clipToPadding"; - public static final String LayoutMode = "layoutMode"; - public static final String SplitMotionEvents = "splitMotionEvents"; - } + public static class ViewGroup { + public static final String Children = "children"; + public static final String ClipChildren = "clipChildren"; + public static final String ClipToPadding = "clipToPadding"; + public static final String LayoutMode = "layoutMode"; + public static final String SplitMotionEvents = "splitMotionEvents"; + } - public static class LinearLayout { - public static final String Orientation = "orientation"; - public static final String Divider = "divider"; - public static final String DividerPadding = "dividerPadding"; - public static final String ShowDividers = "showDividers"; - public static final String WeightSum = "weightSum"; - } + public static class LinearLayout { + public static final String Orientation = "orientation"; + public static final String Divider = "divider"; + public static final String DividerPadding = "dividerPadding"; + public static final String ShowDividers = "showDividers"; + public static final String WeightSum = "weightSum"; + } - public static class ScrollView { - public static final String Scrollbars = "scrollbars"; - } + public static class ScrollView { + public static final String Scrollbars = "scrollbars"; + } - public static class HorizontalScrollView { - public static final String FillViewPort = "fillViewPort"; - } + public static class HorizontalScrollView { + public static final String FillViewPort = "fillViewPort"; + } - public static class ProgressBar { - public static final String Progress = "progress"; - public static final String Max = "max"; - public static final String ProgressTint = "progressTint"; - public static final String IndeterminateTint = "indeterminateTint"; - public static final String SecondaryProgressTint = "secondaryProgressTint"; - } + public static class ProgressBar { + public static final String Progress = "progress"; + public static final String Max = "max"; + public static final String ProgressTint = "progressTint"; + public static final String IndeterminateTint = "indeterminateTint"; + public static final String SecondaryProgressTint = "secondaryProgressTint"; + } } \ No newline at end of file diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/BiMap.java b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/BiMap.java index 151fb669..b90c7c7a 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/BiMap.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/BiMap.java @@ -30,23 +30,23 @@ public interface BiMap { - @Nullable - V put(@Nullable K key, @Nullable V value); + @Nullable + V put(@Nullable K key, @Nullable V value); - @Nullable - V put(@Nullable K key, @Nullable V value, boolean force); + @Nullable + V put(@Nullable K key, @Nullable V value, boolean force); - @Nullable - V getValue(@NonNull K key); + @Nullable + V getValue(@NonNull K key); - @Nullable - K getKey(@NonNull V value); + @Nullable + K getKey(@NonNull V value); - void putAll(@NonNull Map map); + void putAll(@NonNull Map map); - @NonNull - Set values(); + @NonNull + Set values(); - @NonNull - BiMap inverse(); + @NonNull + BiMap inverse(); } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/HashBiMap.java b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/HashBiMap.java index b66decdc..706601b9 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/HashBiMap.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/HashBiMap.java @@ -31,72 +31,72 @@ public class HashBiMap implements BiMap { - private final HashMap map; - private final HashMap inverse; - - public HashBiMap() { - map = new HashMap<>(); - inverse = new HashMap<>(); + private final HashMap map; + private final HashMap inverse; + + public HashBiMap() { + map = new HashMap<>(); + inverse = new HashMap<>(); + } + + public HashBiMap(int initialCapacity) { + map = new HashMap<>(initialCapacity); + inverse = new HashMap<>(initialCapacity); + } + + public HashBiMap(int initialCapacity, float loadFactor) { + map = new HashMap<>(initialCapacity, loadFactor); + inverse = new HashMap<>(initialCapacity, loadFactor); + } + + @Nullable + @Override + public V put(@Nullable K key, @Nullable V value) { + return put(key, value, false); + } + + @Nullable + @Override + public V put(@Nullable K key, @Nullable V value, boolean force) { + if (force && inverse.containsKey(value)) { + throw new IllegalStateException(value + " is already exists!"); } - - public HashBiMap(int initialCapacity) { - map = new HashMap<>(initialCapacity); - inverse = new HashMap<>(initialCapacity); + inverse.put(value, key); + return map.put(key, value); + } + + @Nullable + @Override + public V getValue(@NonNull K key) { + return map.get(key); + } + + @Nullable + @Override + public K getKey(@NonNull V value) { + return inverse.get(value); + } + + @Override + public void putAll(@NonNull Map map) { + for (Map.Entry entry : map.entrySet()) { + put(entry.getKey(), entry.getValue()); } - - public HashBiMap(int initialCapacity, float loadFactor) { - map = new HashMap<>(initialCapacity, loadFactor); - inverse = new HashMap<>(initialCapacity, loadFactor); - } - - @Nullable - @Override - public V put(@Nullable K key, @Nullable V value) { - return put(key, value, false); - } - - @Nullable - @Override - public V put(@Nullable K key, @Nullable V value, boolean force) { - if (force && inverse.containsKey(value)) { - throw new IllegalStateException(value + " is already exists!"); - } - inverse.put(value, key); - return map.put(key, value); - } - - @Nullable - @Override - public V getValue(@NonNull K key) { - return map.get(key); - } - - @Nullable - @Override - public K getKey(@NonNull V value) { - return inverse.get(value); - } - - @Override - public void putAll(@NonNull Map map) { - for (Map.Entry entry : map.entrySet()) { - put(entry.getKey(), entry.getValue()); - } - } - - @NonNull - @Override - public Set values() { - return inverse.keySet(); - } - - @NonNull - @Override - public BiMap inverse() { - BiMap temp = new HashBiMap<>(inverse.size()); - for (Map.Entry entry : map.entrySet()) { - temp.put(entry.getValue(), entry.getKey()); - } - return temp; + } + + @NonNull + @Override + public Set values() { + return inverse.keySet(); + } + + @NonNull + @Override + public BiMap inverse() { + BiMap temp = new HashBiMap<>(inverse.size()); + for (Map.Entry entry : map.entrySet()) { + temp.put(entry.getValue(), entry.getKey()); } + return temp; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/LazilyParsedNumber.java b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/LazilyParsedNumber.java index 0df893ea..4bcbbecc 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/LazilyParsedNumber.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/LazilyParsedNumber.java @@ -31,67 +31,67 @@ public class LazilyParsedNumber extends Number { - private final String value; + private final String value; - /** - * @param value must not be null - */ - public LazilyParsedNumber(String value) { - this.value = value; - } + /** + * @param value must not be null + */ + public LazilyParsedNumber(String value) { + this.value = value; + } - @Override - public int intValue() { - try { - return Integer.parseInt(value); - } catch (NumberFormatException e) { - try { - return (int) Long.parseLong(value); - } catch (NumberFormatException nfe) { - return new BigDecimal(value).intValue(); - } - } + @Override + public int intValue() { + try { + return Integer.parseInt(value); + } catch (NumberFormatException e) { + try { + return (int) Long.parseLong(value); + } catch (NumberFormatException nfe) { + return new BigDecimal(value).intValue(); + } } + } - @Override - public long longValue() { - try { - return Long.parseLong(value); - } catch (NumberFormatException e) { - return new BigDecimal(value).longValue(); - } + @Override + public long longValue() { + try { + return Long.parseLong(value); + } catch (NumberFormatException e) { + return new BigDecimal(value).longValue(); } + } - @Override - public float floatValue() { - return Float.parseFloat(value); - } + @Override + public float floatValue() { + return Float.parseFloat(value); + } - @Override - public double doubleValue() { - return Double.parseDouble(value); - } + @Override + public double doubleValue() { + return Double.parseDouble(value); + } - @Override - public String toString() { - return value; - } + @Override + public String toString() { + return value; + } - @Override - public int hashCode() { - return value.hashCode(); - } + @Override + public int hashCode() { + return value.hashCode(); + } - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof LazilyParsedNumber) { - LazilyParsedNumber other = (LazilyParsedNumber) obj; - //noinspection StringEquality - return value == other.value || value.equals(other.value); - } - return false; + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof LazilyParsedNumber) { + LazilyParsedNumber other = (LazilyParsedNumber) obj; + //noinspection StringEquality + return value == other.value || value.equals(other.value); } + return false; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/ManagerWrapper.java b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/ManagerWrapper.java index 897adefc..e260562b 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/ManagerWrapper.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/ManagerWrapper.java @@ -38,53 +38,53 @@ */ public class ManagerWrapper implements ProteusView.Manager { - private final ProteusView.Manager base; + private final ProteusView.Manager base; - public ManagerWrapper(ProteusView.Manager base) { - this.base = base; - } + public ManagerWrapper(ProteusView.Manager base) { + this.base = base; + } - @Override - public void update(@Nullable ObjectValue data) { - base.update(data); - } + @Override + public void update(@Nullable ObjectValue data) { + base.update(data); + } - @Nullable - @Override - public View findViewById(@NonNull String id) { - return base.findViewById(id); - } + @Nullable + @Override + public View findViewById(@NonNull String id) { + return base.findViewById(id); + } - @NonNull - @Override - public ProteusContext getContext() { - return base.getContext(); - } + @NonNull + @Override + public ProteusContext getContext() { + return base.getContext(); + } - @NonNull - @Override - public Layout getLayout() { - return base.getLayout(); - } + @NonNull + @Override + public Layout getLayout() { + return base.getLayout(); + } - @NonNull - @Override - public DataContext getDataContext() { - return base.getDataContext(); - } + @NonNull + @Override + public DataContext getDataContext() { + return base.getDataContext(); + } - @Nullable - @Override - public Object getExtras() { - return base.getExtras(); - } + @Nullable + @Override + public Object getExtras() { + return base.getExtras(); + } - @Override - public void setExtras(@Nullable Object extras) { - base.setExtras(extras); - } + @Override + public void setExtras(@Nullable Object extras) { + base.setExtras(extras); + } - public ProteusView.Manager getBaseManager() { - return base; - } + public ProteusView.Manager getBaseManager() { + return base; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Result.java b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Result.java index d2aaa429..99bc9378 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Result.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Result.java @@ -32,84 +32,84 @@ */ public class Result { - /** - * Indicates that a valid {@link Value} was found at the specified data path. - */ - public static final int RESULT_SUCCESS = 0; - - /** - * Indicates that the object does not have the specified data path. - */ - public static final int RESULT_NO_SUCH_DATA_PATH_EXCEPTION = -1; - - /** - * Indicates that the data path specified is invalid. As an example, looking for a - * property inside a {@link com.flipkart.android.proteus.value.Primitive} or {@link com.flipkart.android.proteus.value.Array}. - */ - public static final int RESULT_INVALID_DATA_PATH_EXCEPTION = -2; - - /** - * Indicates that the data path prematurely led to a {@link com.flipkart.android.proteus.value.Null} - */ - public static final int RESULT_NULL_EXCEPTION = -3; - - /** - * singleton for No Such Data Path Exception. - */ - public static final Result NO_SUCH_DATA_PATH_EXCEPTION = new Result(Result.RESULT_NO_SUCH_DATA_PATH_EXCEPTION, Null.INSTANCE); - - /** - * singleton for Invalid Data Path Exception. - */ - public static final Result INVALID_DATA_PATH_EXCEPTION = new Result(Result.RESULT_INVALID_DATA_PATH_EXCEPTION, Null.INSTANCE); - - /** - * singleton for Null Exception. - */ - public static final Result NULL_EXCEPTION = new Result(Result.RESULT_NULL_EXCEPTION, Null.INSTANCE); - - /** - * Indicates the return status of the method for a given data path. The return value - * will be {@code RESULT_SUCCESS} if and only if the data path exists and contains - * a valid {@link com.flipkart.android.proteus.value.Value}. - */ - - @ResultCode - public final int RESULT_CODE; - /** - * The value at the specified data path. - * {@code value} will be null if {@code RESULT_CODE} != {@code RESULT_SUCCESS} - */ - - @NonNull - public final Value value; - - public Result(@ResultCode int RESULT_CODE, @NonNull Value value) { - this.RESULT_CODE = RESULT_CODE; - this.value = value; - } - - /** - * This method return a {@link Result} object with {@code RESULT_CODE} == {@code RESULT_SUCCESS} - * and {@code Result#value} == {@code value}. - * - * @param value The {@link Value} to be wrapped. - * @return A {@link Result} object with with {@code RESULT_CODE} == {@code RESULT_SUCCESS}. - */ - public static Result success(Value value) { - return new Result(RESULT_SUCCESS, value); - } - - /** - * @return true if and only if {@code RESULT_CODE} == {@code RESULT_SUCCESS}. - */ - public boolean isSuccess() { - return this.RESULT_CODE == RESULT_SUCCESS; - } - - @IntDef({RESULT_INVALID_DATA_PATH_EXCEPTION, RESULT_NO_SUCH_DATA_PATH_EXCEPTION, RESULT_SUCCESS, RESULT_NULL_EXCEPTION}) - @Retention(RetentionPolicy.SOURCE) - public @interface ResultCode { - } + /** + * Indicates that a valid {@link Value} was found at the specified data path. + */ + public static final int RESULT_SUCCESS = 0; + + /** + * Indicates that the object does not have the specified data path. + */ + public static final int RESULT_NO_SUCH_DATA_PATH_EXCEPTION = -1; + + /** + * Indicates that the data path specified is invalid. As an example, looking for a + * property inside a {@link com.flipkart.android.proteus.value.Primitive} or {@link com.flipkart.android.proteus.value.Array}. + */ + public static final int RESULT_INVALID_DATA_PATH_EXCEPTION = -2; + + /** + * Indicates that the data path prematurely led to a {@link com.flipkart.android.proteus.value.Null} + */ + public static final int RESULT_NULL_EXCEPTION = -3; + + /** + * singleton for No Such Data Path Exception. + */ + public static final Result NO_SUCH_DATA_PATH_EXCEPTION = new Result(Result.RESULT_NO_SUCH_DATA_PATH_EXCEPTION, Null.INSTANCE); + + /** + * singleton for Invalid Data Path Exception. + */ + public static final Result INVALID_DATA_PATH_EXCEPTION = new Result(Result.RESULT_INVALID_DATA_PATH_EXCEPTION, Null.INSTANCE); + + /** + * singleton for Null Exception. + */ + public static final Result NULL_EXCEPTION = new Result(Result.RESULT_NULL_EXCEPTION, Null.INSTANCE); + + /** + * Indicates the return status of the method for a given data path. The return value + * will be {@code RESULT_SUCCESS} if and only if the data path exists and contains + * a valid {@link com.flipkart.android.proteus.value.Value}. + */ + + @ResultCode + public final int RESULT_CODE; + /** + * The value at the specified data path. + * {@code value} will be null if {@code RESULT_CODE} != {@code RESULT_SUCCESS} + */ + + @NonNull + public final Value value; + + public Result(@ResultCode int RESULT_CODE, @NonNull Value value) { + this.RESULT_CODE = RESULT_CODE; + this.value = value; + } + + /** + * This method return a {@link Result} object with {@code RESULT_CODE} == {@code RESULT_SUCCESS} + * and {@code Result#value} == {@code value}. + * + * @param value The {@link Value} to be wrapped. + * @return A {@link Result} object with with {@code RESULT_CODE} == {@code RESULT_SUCCESS}. + */ + public static Result success(Value value) { + return new Result(RESULT_SUCCESS, value); + } + + /** + * @return true if and only if {@code RESULT_CODE} == {@code RESULT_SUCCESS}. + */ + public boolean isSuccess() { + return this.RESULT_CODE == RESULT_SUCCESS; + } + + @IntDef({RESULT_INVALID_DATA_PATH_EXCEPTION, RESULT_NO_SUCH_DATA_PATH_EXCEPTION, RESULT_SUCCESS, RESULT_NULL_EXCEPTION}) + @Retention(RetentionPolicy.SOURCE) + public @interface ResultCode { + } } \ No newline at end of file diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/SimpleArrayIterator.java b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/SimpleArrayIterator.java index c8d0682f..3c5c9d51 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/SimpleArrayIterator.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/SimpleArrayIterator.java @@ -26,48 +26,48 @@ public class SimpleArrayIterator implements Iterator { - private final E[] elements; - private int cursor; + private final E[] elements; + private int cursor; - public SimpleArrayIterator(E[] elements) { - this.elements = elements; - cursor = 0; - } + public SimpleArrayIterator(E[] elements) { + this.elements = elements; + cursor = 0; + } - public static Iterator createIntArrayIterator(final int[] elements) { - return new Iterator() { + public static Iterator createIntArrayIterator(final int[] elements) { + return new Iterator() { - private int cursor; + private int cursor; - @Override - public boolean hasNext() { - return cursor < elements.length; - } - - @Override - public Integer next() { - Integer e = elements[cursor]; - cursor++; - return e; - } - }; - } - - @Override - public boolean hasNext() { + @Override + public boolean hasNext() { return cursor < elements.length; - } + } - @Override - public E next() { - E e = elements[cursor]; + @Override + public Integer next() { + Integer e = elements[cursor]; cursor++; return e; - } + } + }; + } + + @Override + public boolean hasNext() { + return cursor < elements.length; + } + + @Override + public E next() { + E e = elements[cursor]; + cursor++; + return e; + } - @Override - public void remove() { - throw new UnsupportedOperationException("remove() is not allowed."); - } + @Override + public void remove() { + throw new UnsupportedOperationException("remove() is not allowed."); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Utils.java b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Utils.java index aee51d3c..c7f3701b 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Utils.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Utils.java @@ -33,84 +33,84 @@ */ public class Utils { - public static final String LIB_NAME = "proteus"; - public static final String VERSION = "5.0.0-SNAPSHOT"; + public static final String LIB_NAME = "proteus"; + public static final String VERSION = "5.0.0-SNAPSHOT"; - public static final int STYLE_NONE = 0; - public static final int STYLE_SINGLE = 1; - public static final int STYLE_DOUBLE = 2; + public static final int STYLE_NONE = 0; + public static final int STYLE_SINGLE = 1; + public static final int STYLE_DOUBLE = 2; - public static ObjectValue addAllEntries(@NonNull ObjectValue destination, @NonNull ObjectValue source) { - for (Map.Entry entry : source.entrySet()) { - if (destination.get(entry.getKey()) != null) { - continue; - } - destination.add(entry.getKey(), entry.getValue()); - } - return destination; + public static ObjectValue addAllEntries(@NonNull ObjectValue destination, @NonNull ObjectValue source) { + for (Map.Entry entry : source.entrySet()) { + if (destination.get(entry.getKey()) != null) { + continue; + } + destination.add(entry.getKey(), entry.getValue()); } + return destination; + } - public static String join(String[] array, String delimiter) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < array.length; i++) { - sb.append(array[i]); - if (i < array.length - 1) { - sb.append(delimiter); - } - } - return sb.toString(); + public static String join(String[] array, String delimiter) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < array.length; i++) { + sb.append(array[i]); + if (i < array.length - 1) { + sb.append(delimiter); + } } + return sb.toString(); + } - public static String join(Array array, String delimiter, @QuoteStyle int style) { - StringBuilder sb = new StringBuilder(); - Value value; - for (int i = 0; i < array.size(); i++) { - value = array.get(i); - if (value.isPrimitive()) { - Primitive primitive = value.getAsPrimitive(); - String string; - switch (style) { - case STYLE_NONE: - string = primitive.getAsString(); - break; - case STYLE_SINGLE: - string = primitive.getAsSingleQuotedString(); - break; - case STYLE_DOUBLE: - string = primitive.getAsDoubleQuotedString(); - break; - default: - string = primitive.getAsString(); - } - sb.append(string); - } else { - sb.append(value.toString()); - } - if (i < array.size() - 1) { - sb.append(delimiter); - } + public static String join(Array array, String delimiter, @QuoteStyle int style) { + StringBuilder sb = new StringBuilder(); + Value value; + for (int i = 0; i < array.size(); i++) { + value = array.get(i); + if (value.isPrimitive()) { + Primitive primitive = value.getAsPrimitive(); + String string; + switch (style) { + case STYLE_NONE: + string = primitive.getAsString(); + break; + case STYLE_SINGLE: + string = primitive.getAsSingleQuotedString(); + break; + case STYLE_DOUBLE: + string = primitive.getAsDoubleQuotedString(); + break; + default: + string = primitive.getAsString(); } - return sb.toString(); + sb.append(string); + } else { + sb.append(value.toString()); + } + if (i < array.size() - 1) { + sb.append(delimiter); + } } + return sb.toString(); + } - public static String join(Array array, String delimiter) { - return join(array, delimiter, STYLE_NONE); - } + public static String join(Array array, String delimiter) { + return join(array, delimiter, STYLE_NONE); + } - public static String join(Value[] array, String delimiter, @QuoteStyle int style) { - return join(new Array(array), delimiter, style); - } + public static String join(Value[] array, String delimiter, @QuoteStyle int style) { + return join(new Array(array), delimiter, style); + } - public static String join(Value[] array, String delimiter) { - return join(new Array(array), delimiter); - } + public static String join(Value[] array, String delimiter) { + return join(new Array(array), delimiter); + } - public static String getVersion() { - return LIB_NAME + ":" + VERSION; - } + public static String getVersion() { + return LIB_NAME + ":" + VERSION; + } - @Retention(RetentionPolicy.SOURCE) - @IntDef({STYLE_NONE, STYLE_SINGLE, STYLE_DOUBLE}) - public @interface QuoteStyle { - } + @Retention(RetentionPolicy.SOURCE) + @IntDef({STYLE_NONE, STYLE_SINGLE, STYLE_DOUBLE}) + public @interface QuoteStyle { + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Array.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Array.java index fa617fee..a9da8390 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Array.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Array.java @@ -32,192 +32,192 @@ public class Array extends Value { - private final List values; - - /** - * Creates an empty Array. - */ - public Array() { - values = new ArrayList<>(); - } - - public Array(Value[] values) { - this.values = Arrays.asList(values); - } - - /** - * Creates an empty Array with a given capacity. - */ - public Array(int capacity) { - values = new ArrayList<>(capacity); - } - - @Override - public Array copy() { - Array result = new Array(values.size()); - for (Value value : values) { - result.add(value.copy()); - } - return result; - } - - /** - * Adds the specified boolean to self. - * - * @param bool the boolean that needs to be added to the array. - */ - public void add(@Nullable Boolean bool) { - values.add(bool == null ? Null.INSTANCE : new Primitive(bool)); - } - - /** - * Adds the specified character to self. - * - * @param character the character that needs to be added to the array. - */ - public void add(@Nullable Character character) { - values.add(character == null ? Null.INSTANCE : new Primitive(character)); - } - - /** - * Adds the specified number to self. - * - * @param number the number that needs to be added to the array. - */ - public void add(@Nullable Number number) { - values.add(number == null ? Null.INSTANCE : new Primitive(number)); - } - - /** - * Adds the specified string to self. - * - * @param string the string that needs to be added to the array. - */ - public void add(@Nullable String string) { - values.add(string == null ? Null.INSTANCE : new Primitive(string)); - } - - /** - * Adds the specified value to self. - * - * @param value the value that needs to be added to the array. - */ - public void add(@Nullable Value value) { - if (value == null) { - value = Null.INSTANCE; - } - values.add(value); - } - - /** - * Adds the specified value to self. - * - * @param value the value that needs to be added to the array. - */ - public void add(int position, @Nullable Value value) { - if (value == null) { - value = Null.INSTANCE; - } - values.add(position, value); - } - - /** - * Adds all the values of the specified array to self. - * - * @param array the array whose values need to be added to the array. - */ - public void addAll(@NonNull Array array) { - values.addAll(array.values); - } - - /** - * Replaces the value at the specified position in this array with the specified value. - * value can be null. - * - * @param index index of the value to replace - * @param value value to be stored at the specified position - * @return the value previously at the specified position - * @throws IndexOutOfBoundsException if the specified index is outside the array bounds - */ - public Value set(int index, @NonNull Value value) { - return values.set(index, value); - } - - /** - * Removes the first occurrence of the specified value from this array, if it is present. - * If the array does not contain the value, it is unchanged. - * - * @param value value to be removed from this array, if present - * @return true if this array contained the specified value, false otherwise - * @since 2.3 - */ - public boolean remove(@NonNull Value value) { - return values.remove(value); - } - - /** - * Removes the value at the specified position in this array. Shifts any subsequent values - * to the left (subtracts one from their indices). Returns the value that was removed from - * the array. - * - * @param index index the index of the value to be removed - * @return the value previously at the specified position - * @throws IndexOutOfBoundsException if the specified index is outside the array bounds - * @since 2.3 - */ - public Value remove(int index) { - return values.remove(index); - } - - /** - * Returns true if this array contains the specified value. - * - * @param value whose presence in this array is to be tested - * @return true if this array contains the specified value. - * @since 2.3 - */ - public boolean contains(@NonNull Value value) { - return values.contains(value); - } - - /** - * Returns the number of values in the array. - * - * @return the number of values in the array. - */ - public int size() { - return values.size(); - } - - /** - * Returns an iterator to navigate the values of the array. Since the array is an ordered list, - * the iterator navigates the values in the order they were inserted. - * - * @return an iterator to navigate the values of the array. - */ - public Iterator iterator() { - return values.iterator(); - } - - /** - * Returns the ith value of the array. - * - * @param i the index of the value that is being sought. - * @return the value present at the ith index. - * @throws IndexOutOfBoundsException if i is negative or greater than or equal to the - * {@link #size()} of the array. - */ - public Value get(int i) { - return values.get(i); - } - - @Override - public boolean equals(java.lang.Object o) { - return (o == this) || (o instanceof Array && ((Array) o).values.equals(values)); - } - - @Override - public int hashCode() { - return values.hashCode(); - } + private final List values; + + /** + * Creates an empty Array. + */ + public Array() { + values = new ArrayList<>(); + } + + public Array(Value[] values) { + this.values = Arrays.asList(values); + } + + /** + * Creates an empty Array with a given capacity. + */ + public Array(int capacity) { + values = new ArrayList<>(capacity); + } + + @Override + public Array copy() { + Array result = new Array(values.size()); + for (Value value : values) { + result.add(value.copy()); + } + return result; + } + + /** + * Adds the specified boolean to self. + * + * @param bool the boolean that needs to be added to the array. + */ + public void add(@Nullable Boolean bool) { + values.add(bool == null ? Null.INSTANCE : new Primitive(bool)); + } + + /** + * Adds the specified character to self. + * + * @param character the character that needs to be added to the array. + */ + public void add(@Nullable Character character) { + values.add(character == null ? Null.INSTANCE : new Primitive(character)); + } + + /** + * Adds the specified number to self. + * + * @param number the number that needs to be added to the array. + */ + public void add(@Nullable Number number) { + values.add(number == null ? Null.INSTANCE : new Primitive(number)); + } + + /** + * Adds the specified string to self. + * + * @param string the string that needs to be added to the array. + */ + public void add(@Nullable String string) { + values.add(string == null ? Null.INSTANCE : new Primitive(string)); + } + + /** + * Adds the specified value to self. + * + * @param value the value that needs to be added to the array. + */ + public void add(@Nullable Value value) { + if (value == null) { + value = Null.INSTANCE; + } + values.add(value); + } + + /** + * Adds the specified value to self. + * + * @param value the value that needs to be added to the array. + */ + public void add(int position, @Nullable Value value) { + if (value == null) { + value = Null.INSTANCE; + } + values.add(position, value); + } + + /** + * Adds all the values of the specified array to self. + * + * @param array the array whose values need to be added to the array. + */ + public void addAll(@NonNull Array array) { + values.addAll(array.values); + } + + /** + * Replaces the value at the specified position in this array with the specified value. + * value can be null. + * + * @param index index of the value to replace + * @param value value to be stored at the specified position + * @return the value previously at the specified position + * @throws IndexOutOfBoundsException if the specified index is outside the array bounds + */ + public Value set(int index, @NonNull Value value) { + return values.set(index, value); + } + + /** + * Removes the first occurrence of the specified value from this array, if it is present. + * If the array does not contain the value, it is unchanged. + * + * @param value value to be removed from this array, if present + * @return true if this array contained the specified value, false otherwise + * @since 2.3 + */ + public boolean remove(@NonNull Value value) { + return values.remove(value); + } + + /** + * Removes the value at the specified position in this array. Shifts any subsequent values + * to the left (subtracts one from their indices). Returns the value that was removed from + * the array. + * + * @param index index the index of the value to be removed + * @return the value previously at the specified position + * @throws IndexOutOfBoundsException if the specified index is outside the array bounds + * @since 2.3 + */ + public Value remove(int index) { + return values.remove(index); + } + + /** + * Returns true if this array contains the specified value. + * + * @param value whose presence in this array is to be tested + * @return true if this array contains the specified value. + * @since 2.3 + */ + public boolean contains(@NonNull Value value) { + return values.contains(value); + } + + /** + * Returns the number of values in the array. + * + * @return the number of values in the array. + */ + public int size() { + return values.size(); + } + + /** + * Returns an iterator to navigate the values of the array. Since the array is an ordered list, + * the iterator navigates the values in the order they were inserted. + * + * @return an iterator to navigate the values of the array. + */ + public Iterator iterator() { + return values.iterator(); + } + + /** + * Returns the ith value of the array. + * + * @param i the index of the value that is being sought. + * @return the value present at the ith index. + * @throws IndexOutOfBoundsException if i is negative or greater than or equal to the + * {@link #size()} of the array. + */ + public Value get(int i) { + return values.get(i); + } + + @Override + public boolean equals(java.lang.Object o) { + return (o == this) || (o instanceof Array && ((Array) o).values.equals(values)); + } + + @Override + public int hashCode() { + return values.hashCode(); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/AttributeResource.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/AttributeResource.java index 1dfcbcab..50cbfc00 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/AttributeResource.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/AttributeResource.java @@ -37,85 +37,85 @@ */ public class AttributeResource extends Value { - public static final AttributeResource NULL = new AttributeResource(-1); + public static final AttributeResource NULL = new AttributeResource(-1); - private static final String ATTR_START_LITERAL = "?"; - private static final String ATTR_LITERAL = "attr/"; - private static final Pattern sAttributePattern = Pattern.compile("(\\?)(\\S*)(:?)(attr/?)(\\S*)", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); - private static final Map sHashMap = new HashMap<>(); + private static final String ATTR_START_LITERAL = "?"; + private static final String ATTR_LITERAL = "attr/"; + private static final Pattern sAttributePattern = Pattern.compile("(\\?)(\\S*)(:?)(attr/?)(\\S*)", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); + private static final Map sHashMap = new HashMap<>(); - public final int attributeId; + public final int attributeId; - private AttributeResource(final int attributeId) { - this.attributeId = attributeId; - } - - private AttributeResource(String value, Context context) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException { - String attributeName; - String packageName = null; - Matcher matcher = sAttributePattern.matcher(value); - - if (matcher.matches()) { - attributeName = matcher.group(5); - packageName = matcher.group(2); - } else { - attributeName = value.substring(1); - } + private AttributeResource(final int attributeId) { + this.attributeId = attributeId; + } - Class clazz; - if (null != packageName && !packageName.isEmpty()) { - packageName = packageName.substring(0, packageName.length() - 1); - } else { - packageName = context.getPackageName(); - } + private AttributeResource(String value, Context context) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException { + String attributeName; + String packageName = null; + Matcher matcher = sAttributePattern.matcher(value); - String className = packageName + ".R$attr"; - clazz = sHashMap.get(className); - if (null == clazz) { - clazz = Class.forName(className); - sHashMap.put(className, clazz); - } - Field field = clazz.getField(attributeName); - attributeId = field.getInt(null); + if (matcher.matches()) { + attributeName = matcher.group(5); + packageName = matcher.group(2); + } else { + attributeName = value.substring(1); } - public static boolean isAttributeResource(String value) { - return value.startsWith(ATTR_START_LITERAL) && value.contains(ATTR_LITERAL); + Class clazz; + if (null != packageName && !packageName.isEmpty()) { + packageName = packageName.substring(0, packageName.length() - 1); + } else { + packageName = context.getPackageName(); } - @Nullable - public static AttributeResource valueOf(String value, Context context) { - AttributeResource attribute = AttributeCache.cache.get(value); - if (null == attribute) { - try { - attribute = new AttributeResource(value, context); - } catch (Exception e) { - if (ProteusConstants.isLoggingEnabled()) { - e.printStackTrace(); - } - attribute = NULL; - } - AttributeCache.cache.put(value, attribute); - } - return NULL == attribute ? null : attribute; + String className = packageName + ".R$attr"; + clazz = sHashMap.get(className); + if (null == clazz) { + clazz = Class.forName(className); + sHashMap.put(className, clazz); } - - @Nullable - public static AttributeResource valueOf(int value) { - return new AttributeResource(value); - } - - public TypedArray apply(@NonNull Context context) { - return context.obtainStyledAttributes(new int[]{attributeId}); - } - - @Override - public Value copy() { - return this; - } - - private static class AttributeCache { - static final LruCache cache = new LruCache<>(16); + Field field = clazz.getField(attributeName); + attributeId = field.getInt(null); + } + + public static boolean isAttributeResource(String value) { + return value.startsWith(ATTR_START_LITERAL) && value.contains(ATTR_LITERAL); + } + + @Nullable + public static AttributeResource valueOf(String value, Context context) { + AttributeResource attribute = AttributeCache.cache.get(value); + if (null == attribute) { + try { + attribute = new AttributeResource(value, context); + } catch (Exception e) { + if (ProteusConstants.isLoggingEnabled()) { + e.printStackTrace(); + } + attribute = NULL; + } + AttributeCache.cache.put(value, attribute); } + return NULL == attribute ? null : attribute; + } + + @Nullable + public static AttributeResource valueOf(int value) { + return new AttributeResource(value); + } + + public TypedArray apply(@NonNull Context context) { + return context.obtainStyledAttributes(new int[]{attributeId}); + } + + @Override + public Value copy() { + return this; + } + + private static class AttributeCache { + static final LruCache cache = new LruCache<>(16); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Binding.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Binding.java index 0210701a..c454c270 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Binding.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Binding.java @@ -50,477 +50,477 @@ @SuppressWarnings("WeakerAccess") public abstract class Binding extends Value { - public static final char BINDING_PREFIX_0 = '@'; - public static final char BINDING_PREFIX_1 = '{'; - public static final char BINDING_SUFFIX = '}'; - - public static final String INDEX = "$index"; - - public static final String ARRAY_DATA_LENGTH_REFERENCE = "$length"; - public static final String ARRAY_DATA_LAST_INDEX_REFERENCE = "$last"; - - public static final Pattern BINDING_PATTERN = Pattern.compile("@\\{fn:(\\S+?)\\(((?:(? 3 - && value.charAt(0) == BINDING_PREFIX_0 - && value.charAt(1) == BINDING_PREFIX_1 - && value.charAt(value.length() - 1) == BINDING_SUFFIX; + public static final char BINDING_PREFIX_0 = '@'; + public static final char BINDING_PREFIX_1 = '{'; + public static final char BINDING_SUFFIX = '}'; + + public static final String INDEX = "$index"; + + public static final String ARRAY_DATA_LENGTH_REFERENCE = "$length"; + public static final String ARRAY_DATA_LAST_INDEX_REFERENCE = "$last"; + + public static final Pattern BINDING_PATTERN = Pattern.compile("@\\{fn:(\\S+?)\\(((?:(? 3 + && value.charAt(0) == BINDING_PREFIX_0 + && value.charAt(1) == BINDING_PREFIX_1 + && value.charAt(value.length() - 1) == BINDING_SUFFIX; + } + + /** + * This function returns a {@code Binding} object holding the + * value extracted from the specified {@code String} + * + * @param value the value to be parsed. + * @param context the {@link Context} of the caller. + * @param manager the {@link FunctionManager} to evaluate function bindings. + */ + public static Binding valueOf(@NonNull final String value, Context context, FunctionManager manager) { + Matcher matcher = BINDING_PATTERN.matcher(value); + if (matcher.find()) { + if (matcher.group(3) != null) { // It is data binding + return DataBinding.valueOf(matcher.group(3)); + } else { // It is function binding + return FunctionBinding.valueOf(matcher.group(1), matcher.group(2), context, manager); + } + } else { + throw new IllegalArgumentException(value + " is not a binding"); } + } + + /** + * This method evaluates the {@code Binding} on the specified {@link Value} and returns + * the evaluated result. If it is unable to evaluate the {@code Binding} successfully it returns + * {@link Null}. + * + * @param context the {@link Context} of the caller. + * @param data the @{link Value} on which the binding will be evaluated. + * @param index the index to use if the {@code Binding} contains {@link #INDEX} as a token. + * @return the evaluated {@link Value}. + */ + @NonNull + public abstract Value evaluate(Context context, Value data, int index); + + /** + * Returns a {@code String} representation of this {@code Binding}. + * This string can be parsed back into a {@code Binding} object using + * the {@link #valueOf(String, Context, FunctionManager)} function. + * + * @return a string representation of this {@code Binding}. + */ + @NonNull + public abstract String toString(); + + /** + * Returns a copy of this {@code Binding}, and since {@code Binding} + * is an immutable this method returns the object itself. + * + * @return the same object + */ + @Override + public Binding copy() { + return this; + } + + + /** + *

+ * DataBinding is a type of {@link Binding} which represents a + * simple data path. eg. @{a.b.c}, @{a.e.f[8]}. + *

+ * + * @author adityasharat + */ + public static class DataBinding extends Binding { + + private static final LruCache DATA_BINDING_CACHE = new LruCache<>(64); - /** - * This function returns a {@code Binding} object holding the - * value extracted from the specified {@code String} - * - * @param value the value to be parsed. - * @param context the {@link Context} of the caller. - * @param manager the {@link FunctionManager} to evaluate function bindings. - */ - public static Binding valueOf(@NonNull final String value, Context context, FunctionManager manager) { - Matcher matcher = BINDING_PATTERN.matcher(value); - if (matcher.find()) { - if (matcher.group(3) != null) { // It is data binding - return DataBinding.valueOf(matcher.group(3)); - } else { // It is function binding - return FunctionBinding.valueOf(matcher.group(1), matcher.group(2), context, manager); - } - } else { - throw new IllegalArgumentException(value + " is not a binding"); - } + @NonNull + private final Token[] tokens; + + private DataBinding(@NonNull Token[] tokens) { + this.tokens = tokens; } - /** - * This method evaluates the {@code Binding} on the specified {@link Value} and returns - * the evaluated result. If it is unable to evaluate the {@code Binding} successfully it returns - * {@link Null}. - * - * @param context the {@link Context} of the caller. - * @param data the @{link Value} on which the binding will be evaluated. - * @param index the index to use if the {@code Binding} contains {@link #INDEX} as a token. - * @return the evaluated {@link Value}. - */ - @NonNull - public abstract Value evaluate(Context context, Value data, int index); - - /** - * Returns a {@code String} representation of this {@code Binding}. - * This string can be parsed back into a {@code Binding} object using - * the {@link #valueOf(String, Context, FunctionManager)} function. - * - * @return a string representation of this {@code Binding}. - */ @NonNull - public abstract String toString(); - - /** - * Returns a copy of this {@code Binding}, and since {@code Binding} - * is an immutable this method returns the object itself. - * - * @return the same object - */ - @Override - public Binding copy() { - return this; + public static DataBinding valueOf(@NonNull String path) { + DataBinding binding = DATA_BINDING_CACHE.get(path); + if (null == binding) { + StringTokenizer tokenizer = new StringTokenizer(path, DATA_PATH_DELIMITERS, true); + Token[] tokens = new Token[0]; + String token; + char first; + int length; + while (tokenizer.hasMoreTokens()) { + token = tokenizer.nextToken(); + length = token.length(); + first = token.charAt(0); + if (length == 1 && first == DELIMITER_OBJECT) { + continue; + } + if (length == 1 && first == DELIMITER_ARRAY_CLOSING) { + tokens = correctPreviousToken(tokens); + continue; + } + tokens = Arrays.copyOf(tokens, tokens.length + 1); + tokens[tokens.length - 1] = new Token(token, false, false); + } + binding = new DataBinding(tokens); + DATA_BINDING_CACHE.put(path, binding); + } + return binding; } + private static void assign(Token[] tokens, @NonNull Value value, @NonNull Value data, int dataIndex) { + Value current = data; + Token token; + int index = dataIndex; + + for (int i = 0; i < tokens.length - 1; i++) { + token = tokens[i]; + if (token.isArrayIndex) { + try { + index = getArrayIndex(token.value, dataIndex); + } catch (NumberFormatException e) { + return; + } + current = getArrayItem(current.getAsArray(), index, token.isArray); + } else if (token.isArray) { + current = getArray(current, token.value, index); + } else { + current = getObject(current, token, index); + } + } - /** - *

- * DataBinding is a type of {@link Binding} which represents a - * simple data path. eg. @{a.b.c}, @{a.e.f[8]}. - *

- * - * @author adityasharat - */ - public static class DataBinding extends Binding { - - private static final LruCache DATA_BINDING_CACHE = new LruCache<>(64); - - @NonNull - private final Token[] tokens; + token = tokens[tokens.length - 1]; - private DataBinding(@NonNull Token[] tokens) { - this.tokens = tokens; + if (token.isArrayIndex) { + try { + index = getArrayIndex(token.value, dataIndex); + } catch (NumberFormatException e) { + return; } + getArrayItem(current.getAsArray(), index, false); + current.getAsArray().remove(index); + current.getAsArray().add(index, value); + } else { + current.getAsObject().add(token.value, value); + } + } - @NonNull - public static DataBinding valueOf(@NonNull String path) { - DataBinding binding = DATA_BINDING_CACHE.get(path); - if (null == binding) { - StringTokenizer tokenizer = new StringTokenizer(path, DATA_PATH_DELIMITERS, true); - Token[] tokens = new Token[0]; - String token; - char first; - int length; - while (tokenizer.hasMoreTokens()) { - token = tokenizer.nextToken(); - length = token.length(); - first = token.charAt(0); - if (length == 1 && first == DELIMITER_OBJECT) { - continue; - } - if (length == 1 && first == DELIMITER_ARRAY_CLOSING) { - tokens = correctPreviousToken(tokens); - continue; - } - tokens = Arrays.copyOf(tokens, tokens.length + 1); - tokens[tokens.length - 1] = new Token(token, false, false); - } - binding = new DataBinding(tokens); - DATA_BINDING_CACHE.put(path, binding); - } - return binding; + @NonNull + private static Value getObject(Value parent, Token token, int index) { + Value temp; + ObjectValue object; + if (parent.isArray()) { + temp = parent.getAsArray().get(index); + if (temp != null && temp.isObject()) { + object = temp.getAsObject(); + } else { + object = new ObjectValue(); + parent.getAsArray().remove(index); + parent.getAsArray().add(index, object); } - - private static void assign(Token[] tokens, @NonNull Value value, @NonNull Value data, int dataIndex) { - Value current = data; - Token token; - int index = dataIndex; - - for (int i = 0; i < tokens.length - 1; i++) { - token = tokens[i]; - if (token.isArrayIndex) { - try { - index = getArrayIndex(token.value, dataIndex); - } catch (NumberFormatException e) { - return; - } - current = getArrayItem(current.getAsArray(), index, token.isArray); - } else if (token.isArray) { - current = getArray(current, token.value, index); - } else { - current = getObject(current, token, index); - } - } - - token = tokens[tokens.length - 1]; - - if (token.isArrayIndex) { - try { - index = getArrayIndex(token.value, dataIndex); - } catch (NumberFormatException e) { - return; - } - getArrayItem(current.getAsArray(), index, false); - current.getAsArray().remove(index); - current.getAsArray().add(index, value); - } else { - current.getAsObject().add(token.value, value); - } + } else { + temp = parent.getAsObject().get(token.value); + if (temp != null && temp.isObject()) { + object = temp.getAsObject(); + } else { + object = new ObjectValue(); + parent.getAsObject().add(token.value, object); } - @NonNull - private static Value getObject(Value parent, Token token, int index) { - Value temp; - ObjectValue object; - if (parent.isArray()) { - temp = parent.getAsArray().get(index); - if (temp != null && temp.isObject()) { - object = temp.getAsObject(); - } else { - object = new ObjectValue(); - parent.getAsArray().remove(index); - parent.getAsArray().add(index, object); - } - } else { - temp = parent.getAsObject().get(token.value); - if (temp != null && temp.isObject()) { - object = temp.getAsObject(); - } else { - object = new ObjectValue(); - parent.getAsObject().add(token.value, object); - } + } + return object; + } - } - return object; + @NonNull + private static Array getArray(Value parent, String token, int index) { + Value temp; + Array array; + if (parent.isArray()) { + temp = parent.getAsArray().get(index); + if (temp != null && temp.isArray()) { + array = temp.getAsArray(); + } else { + array = new Array(); + parent.getAsArray().remove(index); + parent.getAsArray().add(index, array); } - - @NonNull - private static Array getArray(Value parent, String token, int index) { - Value temp; - Array array; - if (parent.isArray()) { - temp = parent.getAsArray().get(index); - if (temp != null && temp.isArray()) { - array = temp.getAsArray(); - } else { - array = new Array(); - parent.getAsArray().remove(index); - parent.getAsArray().add(index, array); - } - } else { - temp = parent.getAsObject().get(token); - if (temp != null && temp.isArray()) { - array = temp.getAsArray(); - } else { - array = new Array(); - parent.getAsObject().add(token, array); - } - } - return array; + } else { + temp = parent.getAsObject().get(token); + if (temp != null && temp.isArray()) { + array = temp.getAsArray(); + } else { + array = new Array(); + parent.getAsObject().add(token, array); } + } + return array; + } - @NonNull - private static Value getArrayItem(Array array, int index, boolean isArray) { - if (index >= array.size()) { - while (array.size() < index) { - array.add(Null.INSTANCE); - } - if (isArray) { - array.add(new Array()); - } else { - array.add(new ObjectValue()); - } - } - return array.get(index); + @NonNull + private static Value getArrayItem(Array array, int index, boolean isArray) { + if (index >= array.size()) { + while (array.size() < index) { + array.add(Null.INSTANCE); } - - private static int getArrayIndex(@NonNull String token, int dataIndex) throws NumberFormatException { - int index; - if (INDEX.equals(token)) { - index = dataIndex; - } else { - index = Integer.parseInt(token); - } - return index; + if (isArray) { + array.add(new Array()); + } else { + array.add(new ObjectValue()); } + } + return array.get(index); + } + + private static int getArrayIndex(@NonNull String token, int dataIndex) throws NumberFormatException { + int index; + if (INDEX.equals(token)) { + index = dataIndex; + } else { + index = Integer.parseInt(token); + } + return index; + } - @NonNull - private static Token[] correctPreviousToken(Token[] tokens) { - Token previous = tokens[tokens.length - 1]; - int index = previous.value.indexOf(DELIMITER_ARRAY_OPENING); - String prefix = previous.value.substring(0, index); - String suffix = previous.value.substring(index + 1, previous.value.length()); + @NonNull + private static Token[] correctPreviousToken(Token[] tokens) { + Token previous = tokens[tokens.length - 1]; + int index = previous.value.indexOf(DELIMITER_ARRAY_OPENING); + String prefix = previous.value.substring(0, index); + String suffix = previous.value.substring(index + 1, previous.value.length()); + + if (prefix.equals(ProteusConstants.EMPTY)) { + Token token = tokens[tokens.length - 1]; + tokens[tokens.length - 1] = new Token(token.value, true, false); + } else { + tokens[tokens.length - 1] = new Token(prefix, true, false); + } + + tokens = Arrays.copyOf(tokens, tokens.length + 1); + tokens[tokens.length - 1] = new Token(suffix, false, true); + + return tokens; + } - if (prefix.equals(ProteusConstants.EMPTY)) { - Token token = tokens[tokens.length - 1]; - tokens[tokens.length - 1] = new Token(token.value, true, false); + @NonNull + private static Result resolve(Token[] tokens, Value data, int index) { + // replace INDEX with index value + if (tokens.length == 1 && INDEX.equals(tokens[0].value)) { + return Result.success(new Primitive(String.valueOf(index))); + } else { + Value elementToReturn = data; + Value tempElement; + Array tempArray; + + for (int i = 0; i < tokens.length; i++) { + String segment = tokens[i].value; + if (elementToReturn == null) { + return Result.NO_SUCH_DATA_PATH_EXCEPTION; + } + if (elementToReturn.isNull()) { + return Result.NULL_EXCEPTION; + } + if ("".equals(segment)) { + continue; + } + if (elementToReturn.isArray()) { + tempArray = elementToReturn.getAsArray(); + + if (INDEX.equals(segment)) { + if (index < tempArray.size()) { + elementToReturn = tempArray.get(index); + } else { + return Result.NO_SUCH_DATA_PATH_EXCEPTION; + } + } else if (ARRAY_DATA_LENGTH_REFERENCE.equals(segment)) { + elementToReturn = new Primitive(tempArray.size()); + } else if (ARRAY_DATA_LAST_INDEX_REFERENCE.equals(segment)) { + if (tempArray.size() == 0) { + return Result.NO_SUCH_DATA_PATH_EXCEPTION; + } + elementToReturn = tempArray.get(tempArray.size() - 1); } else { - tokens[tokens.length - 1] = new Token(prefix, true, false); + try { + index = Integer.parseInt(segment); + } catch (NumberFormatException e) { + return Result.INVALID_DATA_PATH_EXCEPTION; + } + if (index < tempArray.size()) { + elementToReturn = tempArray.get(index); + } else { + return Result.NO_SUCH_DATA_PATH_EXCEPTION; + } } - - tokens = Arrays.copyOf(tokens, tokens.length + 1); - tokens[tokens.length - 1] = new Token(suffix, false, true); - - return tokens; - } - - @NonNull - private static Result resolve(Token[] tokens, Value data, int index) { - // replace INDEX with index value - if (tokens.length == 1 && INDEX.equals(tokens[0].value)) { - return Result.success(new Primitive(String.valueOf(index))); + } else if (elementToReturn.isObject()) { + tempElement = elementToReturn.getAsObject().get(segment); + if (tempElement != null) { + elementToReturn = tempElement; } else { - Value elementToReturn = data; - Value tempElement; - Array tempArray; - - for (int i = 0; i < tokens.length; i++) { - String segment = tokens[i].value; - if (elementToReturn == null) { - return Result.NO_SUCH_DATA_PATH_EXCEPTION; - } - if (elementToReturn.isNull()) { - return Result.NULL_EXCEPTION; - } - if ("".equals(segment)) { - continue; - } - if (elementToReturn.isArray()) { - tempArray = elementToReturn.getAsArray(); - - if (INDEX.equals(segment)) { - if (index < tempArray.size()) { - elementToReturn = tempArray.get(index); - } else { - return Result.NO_SUCH_DATA_PATH_EXCEPTION; - } - } else if (ARRAY_DATA_LENGTH_REFERENCE.equals(segment)) { - elementToReturn = new Primitive(tempArray.size()); - } else if (ARRAY_DATA_LAST_INDEX_REFERENCE.equals(segment)) { - if (tempArray.size() == 0) { - return Result.NO_SUCH_DATA_PATH_EXCEPTION; - } - elementToReturn = tempArray.get(tempArray.size() - 1); - } else { - try { - index = Integer.parseInt(segment); - } catch (NumberFormatException e) { - return Result.INVALID_DATA_PATH_EXCEPTION; - } - if (index < tempArray.size()) { - elementToReturn = tempArray.get(index); - } else { - return Result.NO_SUCH_DATA_PATH_EXCEPTION; - } - } - } else if (elementToReturn.isObject()) { - tempElement = elementToReturn.getAsObject().get(segment); - if (tempElement != null) { - elementToReturn = tempElement; - } else { - return Result.NO_SUCH_DATA_PATH_EXCEPTION; - } - } else if (elementToReturn.isPrimitive()) { - return Result.INVALID_DATA_PATH_EXCEPTION; - } else { - return Result.NO_SUCH_DATA_PATH_EXCEPTION; - } - } - if (elementToReturn.isNull()) { - return Result.NULL_EXCEPTION; - } - return Result.success(elementToReturn); + return Result.NO_SUCH_DATA_PATH_EXCEPTION; } + } else if (elementToReturn.isPrimitive()) { + return Result.INVALID_DATA_PATH_EXCEPTION; + } else { + return Result.NO_SUCH_DATA_PATH_EXCEPTION; + } } - - @NonNull - @Override - public Value evaluate(Context context, Value data, int index) { - Result result = resolve(tokens, data, index); - return result.isSuccess() ? result.value : Null.INSTANCE; + if (elementToReturn.isNull()) { + return Result.NULL_EXCEPTION; } + return Result.success(elementToReturn); + } + } - @NonNull - @Override - public String toString() { + @NonNull + @Override + public Value evaluate(Context context, Value data, int index) { + Result result = resolve(tokens, data, index); + return result.isSuccess() ? result.value : Null.INSTANCE; + } - //noinspection StringBufferReplaceableByString - return new StringBuilder() - .append(BINDING_PREFIX_0) - .append(BINDING_PREFIX_1) - .append(Utils.join(Token.getValues(tokens), String.valueOf(DELIMITER_OBJECT))) - .append(BINDING_SUFFIX).toString(); - } + @NonNull + @Override + public String toString() { + + //noinspection StringBufferReplaceableByString + return new StringBuilder() + .append(BINDING_PREFIX_0) + .append(BINDING_PREFIX_1) + .append(Utils.join(Token.getValues(tokens), String.valueOf(DELIMITER_OBJECT))) + .append(BINDING_SUFFIX).toString(); + } - public Iterator getTokens() { - return new SimpleArrayIterator<>(this.tokens); - } + public Iterator getTokens() { + return new SimpleArrayIterator<>(this.tokens); + } - public void assign(Value value, Value data, int index) { - assign(tokens, value, data, index); - } + public void assign(Value value, Value data, int index) { + assign(tokens, value, data, index); } + } + + /** + *

+ * FunctionBinding is a type of {@link Binding} which represents a + * function call. eg. @{ fn:add(1,2) }, @{ fn:and(@{a.b}, @{a.c}) }. + * The format is @{ fn<name>:(<arguments>) }, where <name> + * is the name of the function and <arguments> is are comma separated + * arguments. Note that the arguments can be values (strings should be in single quotes) or + * {@link DataBinding} but NOT {@code FunctionBinding}. + *

+ * + * @author adityasharat + */ + public static class FunctionBinding extends Binding { - /** - *

- * FunctionBinding is a type of {@link Binding} which represents a - * function call. eg. @{ fn:add(1,2) }, @{ fn:and(@{a.b}, @{a.c}) }. - * The format is @{ fn<name>:(<arguments>) }, where <name> - * is the name of the function and <arguments> is are comma separated - * arguments. Note that the arguments can be values (strings should be in single quotes) or - * {@link DataBinding} but NOT {@code FunctionBinding}. - *

- * - * @author adityasharat - */ - public static class FunctionBinding extends Binding { - - @NonNull - public final Function function; - - @Nullable - private final Value[] arguments; - - public FunctionBinding(@NonNull Function function, @Nullable Value[] arguments) { - this.arguments = arguments; - this.function = function; - } + @NonNull + public final Function function; - public static FunctionBinding valueOf(@NonNull String name, @NonNull String args, Context context, @NonNull FunctionManager manager) { - Function function = manager.get(name); - String[] tokens = FUNCTION_ARGS_DELIMITER.split(args); - Value[] arguments = new Value[tokens.length]; - String token; - Value resolved; - for (int i = 0; i < tokens.length; i++) { - token = tokens[i].trim(); - if (!token.isEmpty() && token.charAt(0) == '\'') { - token = token.substring(1, token.length() - 1); - resolved = new Primitive(token); - } else { - resolved = AttributeProcessor.staticPreCompile(new Primitive(token), context, manager); - } - arguments[i] = resolved != null ? resolved : new Primitive(token); - } - return new FunctionBinding(function, arguments); + @Nullable + private final Value[] arguments; + + public FunctionBinding(@NonNull Function function, @Nullable Value[] arguments) { + this.arguments = arguments; + this.function = function; + } + + public static FunctionBinding valueOf(@NonNull String name, @NonNull String args, Context context, @NonNull FunctionManager manager) { + Function function = manager.get(name); + String[] tokens = FUNCTION_ARGS_DELIMITER.split(args); + Value[] arguments = new Value[tokens.length]; + String token; + Value resolved; + for (int i = 0; i < tokens.length; i++) { + token = tokens[i].trim(); + if (!token.isEmpty() && token.charAt(0) == '\'') { + token = token.substring(1, token.length() - 1); + resolved = new Primitive(token); + } else { + resolved = AttributeProcessor.staticPreCompile(new Primitive(token), context, manager); } + arguments[i] = resolved != null ? resolved : new Primitive(token); + } + return new FunctionBinding(function, arguments); + } - private static Value[] resolve(Context context, Value[] in, Value data, int index) { + private static Value[] resolve(Context context, Value[] in, Value data, int index) { - //noinspection ConstantConditions because we want it to crash, it is an illegal state anyway - Value[] out = new Value[in.length]; - for (int i = 0; i < in.length; i++) { - out[i] = AttributeProcessor.evaluate(context, in[i], data, index); - } + //noinspection ConstantConditions because we want it to crash, it is an illegal state anyway + Value[] out = new Value[in.length]; + for (int i = 0; i < in.length; i++) { + out[i] = AttributeProcessor.evaluate(context, in[i], data, index); + } - return out; - } + return out; + } - public Iterator getTokens() { - return new SimpleArrayIterator<>(this.arguments); - } + public Iterator getTokens() { + return new SimpleArrayIterator<>(this.arguments); + } - @NonNull - @Override - public Value evaluate(Context context, Value data, int index) { - Value[] arguments = resolve(context, this.arguments, data, index); - try { - return this.function.call(context, data, index, arguments); - } catch (Exception e) { - if (ProteusConstants.isLoggingEnabled()) { - Log.e(Utils.LIB_NAME, e.getMessage(), e); - } - return Null.INSTANCE; - } + @NonNull + @Override + public Value evaluate(Context context, Value data, int index) { + Value[] arguments = resolve(context, this.arguments, data, index); + try { + return this.function.call(context, data, index, arguments); + } catch (Exception e) { + if (ProteusConstants.isLoggingEnabled()) { + Log.e(Utils.LIB_NAME, e.getMessage(), e); } + return Null.INSTANCE; + } + } - @NonNull - @Override - public String toString() { - return String.format("@{fn:%s(%s)}", function.getName(), Utils.join(arguments, ",", Utils.STYLE_SINGLE)); - } + @NonNull + @Override + public String toString() { + return String.format("@{fn:%s(%s)}", function.getName(), Utils.join(arguments, ",", Utils.STYLE_SINGLE)); } + } - public static class Token { + public static class Token { - @NonNull - public final String value; + @NonNull + public final String value; - public final boolean isArray; + public final boolean isArray; - public final boolean isArrayIndex; + public final boolean isArrayIndex; - public final boolean isBinding = false; + public final boolean isBinding = false; - public Token(@NonNull String value, boolean isArray, boolean isArrayIndex) { - this.value = value; - this.isArray = isArray; - this.isArrayIndex = isArrayIndex; - } + public Token(@NonNull String value, boolean isArray, boolean isArrayIndex) { + this.value = value; + this.isArray = isArray; + this.isArrayIndex = isArrayIndex; + } - public static String[] getValues(Token[] tokens) { - String[] values = new String[tokens.length]; - for (int i = 0; i < tokens.length; i++) { - values[i] = tokens[i].value; - } - return values; - } + public static String[] getValues(Token[] tokens) { + String[] values = new String[tokens.length]; + for (int i = 0; i < tokens.length; i++) { + values[i] = tokens[i].value; + } + return values; } + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Color.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Color.java index 1fc49c64..dc0ef6de 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Color.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Color.java @@ -36,289 +36,289 @@ */ public abstract class Color extends Value { - private static final String COLOR_PREFIX_LITERAL = "#"; + private static final String COLOR_PREFIX_LITERAL = "#"; - private static HashMap sAttributesMap = null; + private static HashMap sAttributesMap = null; - @NonNull - public static Color valueOf(@Nullable String value) { - return valueOf(value, Int.BLACK); - } + @NonNull + public static Color valueOf(@Nullable String value) { + return valueOf(value, Int.BLACK); + } - @NonNull - public static Color valueOf(@Nullable String value, @NonNull Color defaultValue) { - if (null == value || value.length() == 0) { - return defaultValue; - } - Color color = ColorCache.cache.get(value); - if (null == color) { - if (isColor(value)) { - @ColorInt int colorInt = android.graphics.Color.parseColor(value); - color = new Int(colorInt); - } else { - color = defaultValue; - } - ColorCache.cache.put(value, color); - } - return color; + @NonNull + public static Color valueOf(@Nullable String value, @NonNull Color defaultValue) { + if (null == value || value.length() == 0) { + return defaultValue; } + Color color = ColorCache.cache.get(value); + if (null == color) { + if (isColor(value)) { + @ColorInt int colorInt = android.graphics.Color.parseColor(value); + color = new Int(colorInt); + } else { + color = defaultValue; + } + ColorCache.cache.put(value, color); + } + return color; + } + + public static Color valueOf(ObjectValue value, Context context) { + if (value.isPrimitive("type")) { + String colorType = value.getAsString("type"); + if (TextUtils.equals(colorType, "selector")) { + + if (value.isArray("children")) { - public static Color valueOf(ObjectValue value, Context context) { - if (value.isPrimitive("type")) { - String colorType = value.getAsString("type"); - if (TextUtils.equals(colorType, "selector")) { - - if (value.isArray("children")) { - - Array children = value.get("children").getAsArray(); - Iterator iterator = children.iterator(); - ObjectValue child; - - int listAllocated = 20; - int listSize = 0; - int[] colorList = new int[listAllocated]; - int[][] stateSpecList = new int[listAllocated][]; - - while (iterator.hasNext()) { - child = iterator.next().getAsObject(); - if (child.size() == 0) { - continue; - } - int j = 0; - Integer baseColor = null; - float alphaMod = 1.0f; - int[] stateSpec = new int[child.size() - 1]; - boolean ignoreItem = false; - - for (Map.Entry entry : child.entrySet()) { - if (ignoreItem) { - break; - } - if (!entry.getValue().isPrimitive()) { - continue; - } - - Integer attributeId = getAttribute(entry.getKey()); - if (null != attributeId) { - switch (attributeId) { - case android.R.attr.type: - if (!TextUtils.equals("item", entry.getValue().getAsString())) { - ignoreItem = true; - } - break; - case android.R.attr.color: - String colorRes = entry.getValue().getAsString(); - if (!TextUtils.isEmpty(colorRes)) { - baseColor = apply(colorRes); - } - break; - case android.R.attr.alpha: - String alphaStr = entry.getValue().getAsString(); - if (!TextUtils.isEmpty(alphaStr)) { - alphaMod = Float.parseFloat(alphaStr); - } - break; - default: - stateSpec[j++] = entry.getValue().getAsBoolean() ? attributeId : -attributeId; - break; - } - } - } - if (!ignoreItem) { - stateSpec = StateSet.trimStateSet(stateSpec, j); - if (null == baseColor) { - throw new IllegalStateException("No ColorValue Specified"); - } - - if (listSize + 1 >= listAllocated) { - listAllocated = idealIntArraySize(listSize + 1); - int[] ncolor = new int[listAllocated]; - System.arraycopy(colorList, 0, ncolor, 0, listSize); - int[][] nstate = new int[listAllocated][]; - System.arraycopy(stateSpecList, 0, nstate, 0, listSize); - colorList = ncolor; - stateSpecList = nstate; - } - - final int color = modulateColorAlpha(baseColor, alphaMod); - - - colorList[listSize] = color; - stateSpecList[listSize] = stateSpec; - listSize++; - } + Array children = value.get("children").getAsArray(); + Iterator iterator = children.iterator(); + ObjectValue child; + + int listAllocated = 20; + int listSize = 0; + int[] colorList = new int[listAllocated]; + int[][] stateSpecList = new int[listAllocated][]; + + while (iterator.hasNext()) { + child = iterator.next().getAsObject(); + if (child.size() == 0) { + continue; + } + int j = 0; + Integer baseColor = null; + float alphaMod = 1.0f; + int[] stateSpec = new int[child.size() - 1]; + boolean ignoreItem = false; + + for (Map.Entry entry : child.entrySet()) { + if (ignoreItem) { + break; + } + if (!entry.getValue().isPrimitive()) { + continue; + } + + Integer attributeId = getAttribute(entry.getKey()); + if (null != attributeId) { + switch (attributeId) { + case android.R.attr.type: + if (!TextUtils.equals("item", entry.getValue().getAsString())) { + ignoreItem = true; } - if (listSize > 0) { - int[] colors = new int[listSize]; - int[][] stateSpecs = new int[listSize][]; - System.arraycopy(colorList, 0, colors, 0, listSize); - System.arraycopy(stateSpecList, 0, stateSpecs, 0, listSize); - return new StateList(stateSpecs, colors); + break; + case android.R.attr.color: + String colorRes = entry.getValue().getAsString(); + if (!TextUtils.isEmpty(colorRes)) { + baseColor = apply(colorRes); } + break; + case android.R.attr.alpha: + String alphaStr = entry.getValue().getAsString(); + if (!TextUtils.isEmpty(alphaStr)) { + alphaMod = Float.parseFloat(alphaStr); + } + break; + default: + stateSpec[j++] = entry.getValue().getAsBoolean() ? attributeId : -attributeId; + break; } + } + } + if (!ignoreItem) { + stateSpec = StateSet.trimStateSet(stateSpec, j); + if (null == baseColor) { + throw new IllegalStateException("No ColorValue Specified"); + } + + if (listSize + 1 >= listAllocated) { + listAllocated = idealIntArraySize(listSize + 1); + int[] ncolor = new int[listAllocated]; + System.arraycopy(colorList, 0, ncolor, 0, listSize); + int[][] nstate = new int[listAllocated][]; + System.arraycopy(stateSpecList, 0, nstate, 0, listSize); + colorList = ncolor; + stateSpecList = nstate; + } + + final int color = modulateColorAlpha(baseColor, alphaMod); + + + colorList[listSize] = color; + stateSpecList[listSize] = stateSpec; + listSize++; } + } + if (listSize > 0) { + int[] colors = new int[listSize]; + int[][] stateSpecs = new int[listSize][]; + System.arraycopy(colorList, 0, colors, 0, listSize); + System.arraycopy(stateSpecList, 0, stateSpecs, 0, listSize); + return new StateList(stateSpecs, colors); + } } - - return Int.BLACK; + } } - private static int apply(String value) { - Color color = valueOf(value); - int colorInt; - if (color instanceof Int) { - colorInt = ((Int) color).value; - } else { - colorInt = Int.BLACK.value; - } - return colorInt; - } + return Int.BLACK; + } - public static boolean isColor(String color) { - return color.startsWith(COLOR_PREFIX_LITERAL); + private static int apply(String value) { + Color color = valueOf(value); + int colorInt; + if (color instanceof Int) { + colorInt = ((Int) color).value; + } else { + colorInt = Int.BLACK.value; } + return colorInt; + } + + public static boolean isColor(String color) { + return color.startsWith(COLOR_PREFIX_LITERAL); + } - private static HashMap getAttributesMap() { + private static HashMap getAttributesMap() { + if (null == sAttributesMap) { + synchronized (Color.class) { if (null == sAttributesMap) { - synchronized (Color.class) { - if (null == sAttributesMap) { - sAttributesMap = new HashMap<>(15); - sAttributesMap.put("type", android.R.attr.type); - sAttributesMap.put("color", android.R.attr.color); - sAttributesMap.put("alpha", android.R.attr.alpha); - sAttributesMap.put("state_pressed", android.R.attr.state_pressed); - sAttributesMap.put("state_focused", android.R.attr.state_focused); - sAttributesMap.put("state_selected", android.R.attr.state_selected); - sAttributesMap.put("state_checkable", android.R.attr.state_checkable); - sAttributesMap.put("state_checked", android.R.attr.state_checked); - sAttributesMap.put("state_enabled", android.R.attr.state_enabled); - sAttributesMap.put("state_window_focused", android.R.attr.state_window_focused); - } - } + sAttributesMap = new HashMap<>(15); + sAttributesMap.put("type", android.R.attr.type); + sAttributesMap.put("color", android.R.attr.color); + sAttributesMap.put("alpha", android.R.attr.alpha); + sAttributesMap.put("state_pressed", android.R.attr.state_pressed); + sAttributesMap.put("state_focused", android.R.attr.state_focused); + sAttributesMap.put("state_selected", android.R.attr.state_selected); + sAttributesMap.put("state_checkable", android.R.attr.state_checkable); + sAttributesMap.put("state_checked", android.R.attr.state_checked); + sAttributesMap.put("state_enabled", android.R.attr.state_enabled); + sAttributesMap.put("state_window_focused", android.R.attr.state_window_focused); } - return sAttributesMap; + } } - - private static Integer getAttribute(String attribute) { - return getAttributesMap().get(attribute); + return sAttributesMap; + } + + private static Integer getAttribute(String attribute) { + return getAttributesMap().get(attribute); + } + + private static int idealByteArraySize(int need) { + for (int i = 4; i < 32; i++) { + if (need <= (1 << i) - 12) { + return (1 << i) - 12; + } } - private static int idealByteArraySize(int need) { - for (int i = 4; i < 32; i++) { - if (need <= (1 << i) - 12) { - return (1 << i) - 12; - } - } - - return need; - } + return need; + } - private static int idealIntArraySize(int need) { - return idealByteArraySize(need * 4) / 4; - } + private static int idealIntArraySize(int need) { + return idealByteArraySize(need * 4) / 4; + } - private static int constrain(int amount, int low, int high) { - return amount < low ? low : (amount > high ? high : amount); - } + private static int constrain(int amount, int low, int high) { + return amount < low ? low : (amount > high ? high : amount); + } - private static int modulateColorAlpha(int baseColor, float alphaMod) { - if (alphaMod == 1.0f) { - return baseColor; - } - final int baseAlpha = android.graphics.Color.alpha(baseColor); - final int alpha = constrain((int) (baseAlpha * alphaMod + 0.5f), 0, 255); - return (baseColor & 0xFFFFFF) | (alpha << 24); + private static int modulateColorAlpha(int baseColor, float alphaMod) { + if (alphaMod == 1.0f) { + return baseColor; } + final int baseAlpha = android.graphics.Color.alpha(baseColor); + final int alpha = constrain((int) (baseAlpha * alphaMod + 0.5f), 0, 255); + return (baseColor & 0xFFFFFF) | (alpha << 24); + } - public abstract Result apply(Context context); + public abstract Result apply(Context context); - private static class ColorCache { - static final LruCache cache = new LruCache<>(64); - } + private static class ColorCache { + static final LruCache cache = new LruCache<>(64); + } - public static class Int extends Color { + public static class Int extends Color { - public static final Int BLACK = new Int(0); + public static final Int BLACK = new Int(0); - @ColorInt - public final int value; + @ColorInt + public final int value; - Int(@ColorInt int value) { - this.value = value; - } + Int(@ColorInt int value) { + this.value = value; + } - public static Int valueOf(int number) { - if (number == 0) { - return BLACK; - } - String value = String.valueOf(number); - Color color = ColorCache.cache.get(value); - if (null == color) { - color = new Int(number); - ColorCache.cache.put(value, color); - } - return (Int) color; - } + public static Int valueOf(int number) { + if (number == 0) { + return BLACK; + } + String value = String.valueOf(number); + Color color = ColorCache.cache.get(value); + if (null == color) { + color = new Int(number); + ColorCache.cache.put(value, color); + } + return (Int) color; + } - @Override - public Value copy() { - return this; - } + @Override + public Value copy() { + return this; + } - @Override - public Result apply(Context context) { - return Result.color(value); - } + @Override + public Result apply(Context context) { + return Result.color(value); } + } - public static class StateList extends Color { + public static class StateList extends Color { - public final int[][] states; - public final int[] colors; + public final int[][] states; + public final int[] colors; - StateList(int[][] states, int[] colors) { - this.states = states; - this.colors = colors; - } + StateList(int[][] states, int[] colors) { + this.states = states; + this.colors = colors; + } - public static StateList valueOf(int[][] states, int[] colors) { - return new StateList(states, colors); - } + public static StateList valueOf(int[][] states, int[] colors) { + return new StateList(states, colors); + } - @Override - public Value copy() { - return this; - } + @Override + public Value copy() { + return this; + } - @Override - public Result apply(Context context) { - ColorStateList colors = new ColorStateList(states, this.colors); - return Result.colors(colors); - } + @Override + public Result apply(Context context) { + ColorStateList colors = new ColorStateList(states, this.colors); + return Result.colors(colors); } + } - public static class Result { + public static class Result { - public final int color; + public final int color; - @Nullable - public final ColorStateList colors; + @Nullable + public final ColorStateList colors; - private Result(int color, @Nullable ColorStateList colors) { - this.color = color; - this.colors = colors; - } + private Result(int color, @Nullable ColorStateList colors) { + this.color = color; + this.colors = colors; + } - public static Result color(int color) { - return create(color, null); - } + public static Result color(int color) { + return create(color, null); + } - public static Result colors(@NonNull ColorStateList colors) { - return create(colors.getDefaultColor(), colors); - } + public static Result colors(@NonNull ColorStateList colors) { + return create(colors.getDefaultColor(), colors); + } - public static Result create(int color, @Nullable ColorStateList colors) { - return new Result(color, colors); - } + public static Result create(int color, @Nullable ColorStateList colors) { + return new Result(color, colors); } + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Dimension.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Dimension.java index 16b610da..3c52ae0e 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Dimension.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Dimension.java @@ -36,145 +36,145 @@ */ public class Dimension extends Value { - public static final int DIMENSION_UNIT_ENUM = -1; - public static final int DIMENSION_UNIT_PX = TypedValue.COMPLEX_UNIT_PX; - public static final int DIMENSION_UNIT_DP = TypedValue.COMPLEX_UNIT_DIP; - public static final int DIMENSION_UNIT_SP = TypedValue.COMPLEX_UNIT_SP; - public static final int DIMENSION_UNIT_PT = TypedValue.COMPLEX_UNIT_PT; - public static final int DIMENSION_UNIT_IN = TypedValue.COMPLEX_UNIT_IN; - public static final int DIMENSION_UNIT_MM = TypedValue.COMPLEX_UNIT_MM; - - public static final String MATCH_PARENT = "match_parent"; - public static final String FILL_PARENT = "fill_parent"; - public static final String WRAP_CONTENT = "wrap_content"; - - public static final String SUFFIX_PX = "px"; - public static final String SUFFIX_DP = "dp"; - public static final String SUFFIX_SP = "sp"; - public static final String SUFFIX_PT = "pt"; - public static final String SUFFIX_IN = "in"; - public static final String SUFFIX_MM = "mm"; - - public static final BiMap sDimensionsMap = new HashBiMap<>(3); - public static final BiMap sDimensionsUnitsMap = new HashBiMap<>(6); - public static final Dimension ZERO = new Dimension(0, DIMENSION_UNIT_PX); - - static { - sDimensionsMap.put(FILL_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); - sDimensionsMap.put(MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); - sDimensionsMap.put(WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); - - sDimensionsUnitsMap.put(SUFFIX_PX, DIMENSION_UNIT_PX); - sDimensionsUnitsMap.put(SUFFIX_DP, DIMENSION_UNIT_DP); - sDimensionsUnitsMap.put(SUFFIX_SP, DIMENSION_UNIT_SP); - sDimensionsUnitsMap.put(SUFFIX_PT, DIMENSION_UNIT_PT); - sDimensionsUnitsMap.put(SUFFIX_IN, DIMENSION_UNIT_IN); - sDimensionsUnitsMap.put(SUFFIX_MM, DIMENSION_UNIT_MM); - } - - public final double value; - public final int unit; - - private Dimension(float value, int unit) { - this.value = value; - this.unit = unit; - } - - private Dimension(String dimension) { - Integer parameter = sDimensionsMap.getValue(dimension); - double value; - int unit; - - if (parameter != null) { - value = parameter; - unit = DIMENSION_UNIT_ENUM; + public static final int DIMENSION_UNIT_ENUM = -1; + public static final int DIMENSION_UNIT_PX = TypedValue.COMPLEX_UNIT_PX; + public static final int DIMENSION_UNIT_DP = TypedValue.COMPLEX_UNIT_DIP; + public static final int DIMENSION_UNIT_SP = TypedValue.COMPLEX_UNIT_SP; + public static final int DIMENSION_UNIT_PT = TypedValue.COMPLEX_UNIT_PT; + public static final int DIMENSION_UNIT_IN = TypedValue.COMPLEX_UNIT_IN; + public static final int DIMENSION_UNIT_MM = TypedValue.COMPLEX_UNIT_MM; + + public static final String MATCH_PARENT = "match_parent"; + public static final String FILL_PARENT = "fill_parent"; + public static final String WRAP_CONTENT = "wrap_content"; + + public static final String SUFFIX_PX = "px"; + public static final String SUFFIX_DP = "dp"; + public static final String SUFFIX_SP = "sp"; + public static final String SUFFIX_PT = "pt"; + public static final String SUFFIX_IN = "in"; + public static final String SUFFIX_MM = "mm"; + + public static final BiMap sDimensionsMap = new HashBiMap<>(3); + public static final BiMap sDimensionsUnitsMap = new HashBiMap<>(6); + public static final Dimension ZERO = new Dimension(0, DIMENSION_UNIT_PX); + + static { + sDimensionsMap.put(FILL_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); + sDimensionsMap.put(MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); + sDimensionsMap.put(WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + + sDimensionsUnitsMap.put(SUFFIX_PX, DIMENSION_UNIT_PX); + sDimensionsUnitsMap.put(SUFFIX_DP, DIMENSION_UNIT_DP); + sDimensionsUnitsMap.put(SUFFIX_SP, DIMENSION_UNIT_SP); + sDimensionsUnitsMap.put(SUFFIX_PT, DIMENSION_UNIT_PT); + sDimensionsUnitsMap.put(SUFFIX_IN, DIMENSION_UNIT_IN); + sDimensionsUnitsMap.put(SUFFIX_MM, DIMENSION_UNIT_MM); + } + + public final double value; + public final int unit; + + private Dimension(float value, int unit) { + this.value = value; + this.unit = unit; + } + + private Dimension(String dimension) { + Integer parameter = sDimensionsMap.getValue(dimension); + double value; + int unit; + + if (parameter != null) { + value = parameter; + unit = DIMENSION_UNIT_ENUM; + } else { + int length = dimension.length(); + if (length < 2) { + value = 0; + unit = DIMENSION_UNIT_PX; + } else { // find the units and value by splitting at the second-last character of the dimension + Integer u = sDimensionsUnitsMap.getValue(dimension.substring(length - 2)); + String stringValue = dimension.substring(0, length - 2); + if (u != null) { + value = ParseHelper.parseFloat(stringValue); + unit = u; } else { - int length = dimension.length(); - if (length < 2) { - value = 0; - unit = DIMENSION_UNIT_PX; - } else { // find the units and value by splitting at the second-last character of the dimension - Integer u = sDimensionsUnitsMap.getValue(dimension.substring(length - 2)); - String stringValue = dimension.substring(0, length - 2); - if (u != null) { - value = ParseHelper.parseFloat(stringValue); - unit = u; - } else { - value = 0; - unit = DIMENSION_UNIT_PX; - } - } + value = 0; + unit = DIMENSION_UNIT_PX; } - - this.value = value; - this.unit = unit; + } } - /** - * This function returns a {@code Dimension} object holding the - * value extracted from the specified {@code String} - * - * @param dimension the value to be parsed. - */ - public static Dimension valueOf(String dimension) { - if (null == dimension) { - return ZERO; - } - Dimension d = DimensionCache.cache.get(dimension); - if (null == d) { - d = new Dimension(dimension); - DimensionCache.cache.put(dimension, d); - } - return d; + this.value = value; + this.unit = unit; + } + + /** + * This function returns a {@code Dimension} object holding the + * value extracted from the specified {@code String} + * + * @param dimension the value to be parsed. + */ + public static Dimension valueOf(String dimension) { + if (null == dimension) { + return ZERO; } - - public static float apply(String dimension, Context context) { - return Dimension.valueOf(dimension).apply(context); + Dimension d = DimensionCache.cache.get(dimension); + if (null == d) { + d = new Dimension(dimension); + DimensionCache.cache.put(dimension, d); } - - public float apply(Context context) { - double result = 0; - - switch (unit) { - case DIMENSION_UNIT_ENUM: - result = value; - break; - case DIMENSION_UNIT_PX: - case DIMENSION_UNIT_DP: - case DIMENSION_UNIT_SP: - case DIMENSION_UNIT_PT: - case DIMENSION_UNIT_MM: - case DIMENSION_UNIT_IN: - result = TypedValue.applyDimension(unit, (float) value, context.getResources().getDisplayMetrics()); - break; - } - - return (float) result; + return d; + } + + public static float apply(String dimension, Context context) { + return Dimension.valueOf(dimension).apply(context); + } + + public float apply(Context context) { + double result = 0; + + switch (unit) { + case DIMENSION_UNIT_ENUM: + result = value; + break; + case DIMENSION_UNIT_PX: + case DIMENSION_UNIT_DP: + case DIMENSION_UNIT_SP: + case DIMENSION_UNIT_PT: + case DIMENSION_UNIT_MM: + case DIMENSION_UNIT_IN: + result = TypedValue.applyDimension(unit, (float) value, context.getResources().getDisplayMetrics()); + break; } - @Override - public Value copy() { - return this; + return (float) result; + } + + @Override + public Value copy() { + return this; + } + + @Override + public String toString() { + final String value; + if (this.value % 1 == 0) { + value = String.valueOf((int) this.value); + } else { + value = String.valueOf(this.value); } - - @Override - public String toString() { - final String value; - if (this.value % 1 == 0) { - value = String.valueOf((int) this.value); - } else { - value = String.valueOf(this.value); - } - final String unit; - if (this.unit == DIMENSION_UNIT_ENUM) { - return sDimensionsMap.getKey((int) this.value); - } else { - unit = sDimensionsUnitsMap.getKey(this.unit); - return value + unit; - } + final String unit; + if (this.unit == DIMENSION_UNIT_ENUM) { + return sDimensionsMap.getKey((int) this.value); + } else { + unit = sDimensionsUnitsMap.getKey(this.unit); + return value + unit; } + } - private static class DimensionCache { - static final LruCache cache = new LruCache<>(64); - } + private static class DimensionCache { + static final LruCache cache = new LruCache<>(64); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/DrawableValue.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/DrawableValue.java index d9eafa4a..c14dbf27 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/DrawableValue.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/DrawableValue.java @@ -55,924 +55,924 @@ */ public abstract class DrawableValue extends Value { - private static final String TYPE = "type"; - private static final String CHILDREN = "children"; - - private static final String DRAWABLE_SELECTOR = "selector"; - private static final String DRAWABLE_SHAPE = "shape"; - private static final String DRAWABLE_LAYER_LIST = "layer-list"; - private static final String DRAWABLE_LEVEL_LIST = "level-list"; - private static final String DRAWABLE_RIPPLE = "ripple"; - - private static final String TYPE_CORNERS = "corners"; - private static final String TYPE_GRADIENT = "gradient"; - private static final String TYPE_PADDING = "padding"; - private static final String TYPE_SIZE = "size"; - private static final String TYPE_SOLID = "solid"; - private static final String TYPE_STROKE = "stroke"; - - @Nullable - public static DrawableValue valueOf(String value, Context context) { - if (Color.isColor(value)) { - return ColorValue.valueOf(value); - } else { - return UrlValue.valueOf(value); - } + private static final String TYPE = "type"; + private static final String CHILDREN = "children"; + + private static final String DRAWABLE_SELECTOR = "selector"; + private static final String DRAWABLE_SHAPE = "shape"; + private static final String DRAWABLE_LAYER_LIST = "layer-list"; + private static final String DRAWABLE_LEVEL_LIST = "level-list"; + private static final String DRAWABLE_RIPPLE = "ripple"; + + private static final String TYPE_CORNERS = "corners"; + private static final String TYPE_GRADIENT = "gradient"; + private static final String TYPE_PADDING = "padding"; + private static final String TYPE_SIZE = "size"; + private static final String TYPE_SOLID = "solid"; + private static final String TYPE_STROKE = "stroke"; + + @Nullable + public static DrawableValue valueOf(String value, Context context) { + if (Color.isColor(value)) { + return ColorValue.valueOf(value); + } else { + return UrlValue.valueOf(value); } - - @Nullable - public static DrawableValue valueOf(ObjectValue value, Context context) { - String type = value.getAsString(TYPE); - //noinspection ConstantConditions - switch (type) { - case DRAWABLE_SELECTOR: - return StateListValue.valueOf(value.getAsArray(CHILDREN), context); - case DRAWABLE_SHAPE: - return ShapeValue.valueOf(value, context); - case DRAWABLE_LAYER_LIST: - return LayerListValue.valueOf(value.getAsArray(CHILDREN), context); - case DRAWABLE_LEVEL_LIST: - return LevelListValue.valueOf(value.getAsArray(CHILDREN), context); - case DRAWABLE_RIPPLE: - return RippleValue.valueOf(value, context); - default: - return null; - } + } + + @Nullable + public static DrawableValue valueOf(ObjectValue value, Context context) { + String type = value.getAsString(TYPE); + //noinspection ConstantConditions + switch (type) { + case DRAWABLE_SELECTOR: + return StateListValue.valueOf(value.getAsArray(CHILDREN), context); + case DRAWABLE_SHAPE: + return ShapeValue.valueOf(value, context); + case DRAWABLE_LAYER_LIST: + return LayerListValue.valueOf(value.getAsArray(CHILDREN), context); + case DRAWABLE_LEVEL_LIST: + return LevelListValue.valueOf(value.getAsArray(CHILDREN), context); + case DRAWABLE_RIPPLE: + return RippleValue.valueOf(value, context); + default: + return null; } + } - @NonNull - public static Drawable convertBitmapToDrawable(Bitmap original, Context context) { - - DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); - int width = original.getWidth(); - int height = original.getHeight(); + @NonNull + public static Drawable convertBitmapToDrawable(Bitmap original, Context context) { - float scaleWidth = displayMetrics.scaledDensity; - float scaleHeight = displayMetrics.scaledDensity; - Matrix matrix = new Matrix(); - matrix.postScale(scaleWidth, scaleHeight); + DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); + int width = original.getWidth(); + int height = original.getHeight(); - Bitmap resizedBitmap = Bitmap.createBitmap(original, 0, 0, width, height, matrix, true); + float scaleWidth = displayMetrics.scaledDensity; + float scaleHeight = displayMetrics.scaledDensity; + Matrix matrix = new Matrix(); + matrix.postScale(scaleWidth, scaleHeight); - return new BitmapDrawable(context.getResources(), resizedBitmap); - } + Bitmap resizedBitmap = Bitmap.createBitmap(original, 0, 0, width, height, matrix, true); - public abstract void apply(ProteusView view, Context context, ProteusLayoutInflater.ImageLoader loader, Callback callback); + return new BitmapDrawable(context.getResources(), resizedBitmap); + } - @Override - public Value copy() { - return this; - } + public abstract void apply(ProteusView view, Context context, ProteusLayoutInflater.ImageLoader loader, Callback callback); - public interface Callback { - void apply(Drawable drawable); - } + @Override + public Value copy() { + return this; + } - public static class ColorValue extends DrawableValue { + public interface Callback { + void apply(Drawable drawable); + } - public static final ColorValue BLACK = new ColorValue(Color.Int.BLACK); + public static class ColorValue extends DrawableValue { - public final Value color; + public static final ColorValue BLACK = new ColorValue(Color.Int.BLACK); - private ColorValue(Value color) { - this.color = color; - } + public final Value color; - public static ColorValue valueOf(String value) { - return new ColorValue(Color.valueOf(value)); - } + private ColorValue(Value color) { + this.color = color; + } - public static ColorValue valueOf(Value value, Context context) { - return new ColorValue(ColorResourceProcessor.staticCompile(value, context)); - } + public static ColorValue valueOf(String value) { + return new ColorValue(Color.valueOf(value)); + } - @Override - public void apply(ProteusView view, Context context, ProteusLayoutInflater.ImageLoader loader, Callback callback) { - Drawable drawable = new ColorDrawable(ColorResourceProcessor.evaluate(color, view).color); - callback.apply(drawable); - } + public static ColorValue valueOf(Value value, Context context) { + return new ColorValue(ColorResourceProcessor.staticCompile(value, context)); } - public static class ShapeValue extends DrawableValue { - - private static final int SHAPE_NONE = -1; - - private static final String SHAPE_RECTANGLE = "rectangle"; - private static final String SHAPE_OVAL = "oval"; - private static final String SHAPE_LINE = "line"; - private static final String SHAPE_RING = "ring"; - - private static final String SHAPE = "shape"; - - public final int shape; - - @Nullable - public final Gradient gradient; - - @Nullable - private final DrawableElement[] elements; - - private ShapeValue(ObjectValue value, Context context) { - this.shape = getShape(value.getAsString(SHAPE)); - - Gradient gradient = null; - Array children = value.getAsArray(CHILDREN); - Iterator iterator = children.iterator(); - - if (children.size() > 0) { - this.elements = new DrawableElement[children.size()]; - int index = 0; - while (iterator.hasNext()) { - ObjectValue child = iterator.next().getAsObject(); - String typeKey = child.getAsString(TYPE); - DrawableElement element = null; - //noinspection ConstantConditions - switch (typeKey) { - case TYPE_CORNERS: - element = Corners.valueOf(child, context); - break; - case TYPE_PADDING: - break; - case TYPE_SIZE: - element = Size.valueOf(child, context); - break; - case TYPE_SOLID: - element = Solid.valueOf(child, context); - break; - case TYPE_STROKE: - element = Stroke.valueOf(child, context); - break; - case TYPE_GRADIENT: - gradient = Gradient.valueOf(child, context); - element = gradient; - break; - } - - if (null != element) { - this.elements[index] = element; - index++; - } - } - this.gradient = gradient; - } else { - this.elements = null; - this.gradient = null; - } - } + @Override + public void apply(ProteusView view, Context context, ProteusLayoutInflater.ImageLoader loader, Callback callback) { + Drawable drawable = new ColorDrawable(ColorResourceProcessor.evaluate(color, view).color); + callback.apply(drawable); + } + } - private ShapeValue(int shape, @Nullable Gradient gradient, @Nullable DrawableElement[] elements) { - this.shape = shape; - this.gradient = gradient; - this.elements = elements; - } + public static class ShapeValue extends DrawableValue { - public static ShapeValue valueOf(ObjectValue value, Context context) { - return new ShapeValue(value, context); - } + private static final int SHAPE_NONE = -1; - public static ShapeValue valueOf(int shape, @Nullable Gradient gradient, @Nullable DrawableElement[] elements) { - return new ShapeValue(shape, gradient, elements); - } + private static final String SHAPE_RECTANGLE = "rectangle"; + private static final String SHAPE_OVAL = "oval"; + private static final String SHAPE_LINE = "line"; + private static final String SHAPE_RING = "ring"; - private static int getShape(String shape) { - switch (shape) { - case SHAPE_RECTANGLE: - return GradientDrawable.RECTANGLE; - case SHAPE_OVAL: - return GradientDrawable.OVAL; - case SHAPE_LINE: - return GradientDrawable.LINE; - case SHAPE_RING: - return GradientDrawable.RING; - default: - return SHAPE_NONE; - - } - } + private static final String SHAPE = "shape"; - @Override - public void apply(ProteusView view, Context context, ProteusLayoutInflater.ImageLoader loader, Callback callback) { - GradientDrawable drawable = null != gradient ? gradient.init(view) : new GradientDrawable(); - if (-1 != shape) { - drawable.setShape(shape); - } - if (null != elements) { - for (DrawableElement element : elements) { - element.apply(view, drawable); - } - } - callback.apply(drawable); - } - } + public final int shape; - public static class LayerListValue extends DrawableValue { + @Nullable + public final Gradient gradient; - private static final String ID_STR = "id"; - private static final String DRAWABLE_STR = "drawable"; + @Nullable + private final DrawableElement[] elements; + + private ShapeValue(ObjectValue value, Context context) { + this.shape = getShape(value.getAsString(SHAPE)); + + Gradient gradient = null; + Array children = value.getAsArray(CHILDREN); + Iterator iterator = children.iterator(); + + if (children.size() > 0) { + this.elements = new DrawableElement[children.size()]; + int index = 0; + while (iterator.hasNext()) { + ObjectValue child = iterator.next().getAsObject(); + String typeKey = child.getAsString(TYPE); + DrawableElement element = null; + //noinspection ConstantConditions + switch (typeKey) { + case TYPE_CORNERS: + element = Corners.valueOf(child, context); + break; + case TYPE_PADDING: + break; + case TYPE_SIZE: + element = Size.valueOf(child, context); + break; + case TYPE_SOLID: + element = Solid.valueOf(child, context); + break; + case TYPE_STROKE: + element = Stroke.valueOf(child, context); + break; + case TYPE_GRADIENT: + gradient = Gradient.valueOf(child, context); + element = gradient; + break; + } + + if (null != element) { + this.elements[index] = element; + index++; + } + } + this.gradient = gradient; + } else { + this.elements = null; + this.gradient = null; + } + } - private final int[] ids; - private final Value[] layers; + private ShapeValue(int shape, @Nullable Gradient gradient, @Nullable DrawableElement[] elements) { + this.shape = shape; + this.gradient = gradient; + this.elements = elements; + } - private LayerListValue(Array layers, Context context) { - this.ids = new int[layers.size()]; - this.layers = new Value[layers.size()]; - Pair pair; - int index = 0; - Iterator iterator = layers.iterator(); - while (iterator.hasNext()) { - pair = parseLayer(iterator.next().getAsObject(), context); - this.ids[index] = pair.first; - this.layers[index] = pair.second; - index++; - } - } + public static ShapeValue valueOf(ObjectValue value, Context context) { + return new ShapeValue(value, context); + } - public LayerListValue(int[] ids, Value[] layers) { - this.ids = ids; - this.layers = layers; - } + public static ShapeValue valueOf(int shape, @Nullable Gradient gradient, @Nullable DrawableElement[] elements) { + return new ShapeValue(shape, gradient, elements); + } - public static LayerListValue valueOf(Array layers, Context context) { - return new LayerListValue(layers, context); - } + private static int getShape(String shape) { + switch (shape) { + case SHAPE_RECTANGLE: + return GradientDrawable.RECTANGLE; + case SHAPE_OVAL: + return GradientDrawable.OVAL; + case SHAPE_LINE: + return GradientDrawable.LINE; + case SHAPE_RING: + return GradientDrawable.RING; + default: + return SHAPE_NONE; + + } + } - public static LayerListValue valueOf(@NonNull int[] ids, @NonNull Value[] layers) { - return new LayerListValue(ids, layers); - } + @Override + public void apply(ProteusView view, Context context, ProteusLayoutInflater.ImageLoader loader, Callback callback) { + GradientDrawable drawable = null != gradient ? gradient.init(view) : new GradientDrawable(); + if (-1 != shape) { + drawable.setShape(shape); + } + if (null != elements) { + for (DrawableElement element : elements) { + element.apply(view, drawable); + } + } + callback.apply(drawable); + } + } + + public static class LayerListValue extends DrawableValue { + + private static final String ID_STR = "id"; + private static final String DRAWABLE_STR = "drawable"; + + private final int[] ids; + private final Value[] layers; + + private LayerListValue(Array layers, Context context) { + this.ids = new int[layers.size()]; + this.layers = new Value[layers.size()]; + Pair pair; + int index = 0; + Iterator iterator = layers.iterator(); + while (iterator.hasNext()) { + pair = parseLayer(iterator.next().getAsObject(), context); + this.ids[index] = pair.first; + this.layers[index] = pair.second; + index++; + } + } - public static Pair parseLayer(ObjectValue layer, Context context) { - String id = layer.getAsString(ID_STR); - int resId = View.NO_ID; - if (id != null) { - resId = ParseHelper.getAndroidXmlResId(id); - } - Value drawable = layer.get(DRAWABLE_STR); - Value out = DrawableResourceProcessor.staticCompile(drawable, context); - return new Pair<>(resId, out); - } + public LayerListValue(int[] ids, Value[] layers) { + this.ids = ids; + this.layers = layers; + } - @Override - public void apply(ProteusView view, Context context, ProteusLayoutInflater.ImageLoader loader, Callback callback) { - final Drawable[] drawables = new Drawable[layers.length]; - int index = 0; - for (Value layer : layers) { - drawables[index] = DrawableResourceProcessor.evaluate(layer, view); - index++; - } - - LayerDrawable layerDrawable = new LayerDrawable(drawables); - - // we could have avoided the following loop if layer drawable - // had a method to add drawable and set id at same time - for (int i = 0; i < drawables.length; i++) { - layerDrawable.setId(i, ids[i]); - } - - callback.apply(layerDrawable); - } + public static LayerListValue valueOf(Array layers, Context context) { + return new LayerListValue(layers, context); + } - public Iterator getIds() { - return SimpleArrayIterator.createIntArrayIterator(ids); - } + public static LayerListValue valueOf(@NonNull int[] ids, @NonNull Value[] layers) { + return new LayerListValue(ids, layers); + } - public Iterator getLayers() { - return new SimpleArrayIterator<>(layers); - } + public static Pair parseLayer(ObjectValue layer, Context context) { + String id = layer.getAsString(ID_STR); + int resId = View.NO_ID; + if (id != null) { + resId = ParseHelper.getAndroidXmlResId(id); + } + Value drawable = layer.get(DRAWABLE_STR); + Value out = DrawableResourceProcessor.staticCompile(drawable, context); + return new Pair<>(resId, out); } - public static class StateListValue extends DrawableValue { + @Override + public void apply(ProteusView view, Context context, ProteusLayoutInflater.ImageLoader loader, Callback callback) { + final Drawable[] drawables = new Drawable[layers.length]; + int index = 0; + for (Value layer : layers) { + drawables[index] = DrawableResourceProcessor.evaluate(layer, view); + index++; + } + + LayerDrawable layerDrawable = new LayerDrawable(drawables); + + // we could have avoided the following loop if layer drawable + // had a method to add drawable and set id at same time + for (int i = 0; i < drawables.length; i++) { + layerDrawable.setId(i, ids[i]); + } + + callback.apply(layerDrawable); + } - private static final String DRAWABLE_STR = "drawable"; - private static final Map sStateMap = new HashMap<>(); + public Iterator getIds() { + return SimpleArrayIterator.createIntArrayIterator(ids); + } - static { - sStateMap.put("state_pressed", android.R.attr.state_pressed); - sStateMap.put("state_enabled", android.R.attr.state_enabled); - sStateMap.put("state_focused", android.R.attr.state_focused); - sStateMap.put("state_hovered", android.R.attr.state_hovered); - sStateMap.put("state_selected", android.R.attr.state_selected); - sStateMap.put("state_checkable", android.R.attr.state_checkable); - sStateMap.put("state_checked", android.R.attr.state_checked); - sStateMap.put("state_activated", android.R.attr.state_activated); - sStateMap.put("state_window_focused", android.R.attr.state_window_focused); - } + public Iterator getLayers() { + return new SimpleArrayIterator<>(layers); + } + } + + public static class StateListValue extends DrawableValue { + + private static final String DRAWABLE_STR = "drawable"; + private static final Map sStateMap = new HashMap<>(); + + static { + sStateMap.put("state_pressed", android.R.attr.state_pressed); + sStateMap.put("state_enabled", android.R.attr.state_enabled); + sStateMap.put("state_focused", android.R.attr.state_focused); + sStateMap.put("state_hovered", android.R.attr.state_hovered); + sStateMap.put("state_selected", android.R.attr.state_selected); + sStateMap.put("state_checkable", android.R.attr.state_checkable); + sStateMap.put("state_checked", android.R.attr.state_checked); + sStateMap.put("state_activated", android.R.attr.state_activated); + sStateMap.put("state_window_focused", android.R.attr.state_window_focused); + } - public final int[][] states; - private final Value[] values; + public final int[][] states; + private final Value[] values; - private StateListValue(int[][] states, Value[] values) { - this.states = states; - this.values = values; - } + private StateListValue(int[][] states, Value[] values) { + this.states = states; + this.values = values; + } - private StateListValue(Array states, Context context) { - this.states = new int[states.size()][]; - this.values = new Value[states.size()]; - Iterator iterator = states.iterator(); - Pair pair; - int index = 0; - while (iterator.hasNext()) { - pair = parseState(iterator.next().getAsObject(), context); - this.states[index] = pair.first; - this.values[index] = pair.second; - index++; - } - } + private StateListValue(Array states, Context context) { + this.states = new int[states.size()][]; + this.values = new Value[states.size()]; + Iterator iterator = states.iterator(); + Pair pair; + int index = 0; + while (iterator.hasNext()) { + pair = parseState(iterator.next().getAsObject(), context); + this.states[index] = pair.first; + this.values[index] = pair.second; + index++; + } + } - public static StateListValue valueOf(int[][] states, Value[] values) { - return new StateListValue(states, values); - } + public static StateListValue valueOf(int[][] states, Value[] values) { + return new StateListValue(states, values); + } - public static StateListValue valueOf(Array states, Context context) { - return new StateListValue(states, context); - } + public static StateListValue valueOf(Array states, Context context) { + return new StateListValue(states, context); + } - @NonNull - private static Pair parseState(ObjectValue value, Context context) { - Value drawable = DrawableResourceProcessor.staticCompile(value.get(DRAWABLE_STR), context); - int[] states = new int[value.getAsObject().entrySet().size() - 1]; - int index = 0; - for (Map.Entry entry : value.getAsObject().entrySet()) { - Integer stateInteger = sStateMap.get(entry.getKey()); - if (stateInteger != null) { - // e.g state_pressed = true state_pressed = false - states[index] = ParseHelper.parseBoolean(entry.getValue()) ? stateInteger : -stateInteger; - index++; - } else { - throw new IllegalArgumentException(entry.getKey() + " is not a valid state"); - } - } - return new Pair<>(states, drawable); + @NonNull + private static Pair parseState(ObjectValue value, Context context) { + Value drawable = DrawableResourceProcessor.staticCompile(value.get(DRAWABLE_STR), context); + int[] states = new int[value.getAsObject().entrySet().size() - 1]; + int index = 0; + for (Map.Entry entry : value.getAsObject().entrySet()) { + Integer stateInteger = sStateMap.get(entry.getKey()); + if (stateInteger != null) { + // e.g state_pressed = true state_pressed = false + states[index] = ParseHelper.parseBoolean(entry.getValue()) ? stateInteger : -stateInteger; + index++; + } else { + throw new IllegalArgumentException(entry.getKey() + " is not a valid state"); } + } + return new Pair<>(states, drawable); + } - @Override - public void apply(ProteusView view, Context context, ProteusLayoutInflater.ImageLoader loader, Callback callback) { - final StateListDrawable stateListDrawable = new StateListDrawable(); - int size = states.length; - for (int i = 0; i < size; i++) { - stateListDrawable.addState(states[i], DrawableResourceProcessor.evaluate(values[i], view)); - } - callback.apply(stateListDrawable); - } + @Override + public void apply(ProteusView view, Context context, ProteusLayoutInflater.ImageLoader loader, Callback callback) { + final StateListDrawable stateListDrawable = new StateListDrawable(); + int size = states.length; + for (int i = 0; i < size; i++) { + stateListDrawable.addState(states[i], DrawableResourceProcessor.evaluate(values[i], view)); + } + callback.apply(stateListDrawable); + } - public Iterator getValues() { - return new SimpleArrayIterator<>(values); - } + public Iterator getValues() { + return new SimpleArrayIterator<>(values); } + } - public static class LevelListValue extends DrawableValue { + public static class LevelListValue extends DrawableValue { - private final Level[] levels; + private final Level[] levels; - private LevelListValue(Array levels, Context context) { - this.levels = new Level[levels.size()]; - int index = 0; - Iterator iterator = levels.iterator(); - while (iterator.hasNext()) { - this.levels[index] = new Level(iterator.next().getAsObject(), context); - index++; - } - } + private LevelListValue(Array levels, Context context) { + this.levels = new Level[levels.size()]; + int index = 0; + Iterator iterator = levels.iterator(); + while (iterator.hasNext()) { + this.levels[index] = new Level(iterator.next().getAsObject(), context); + index++; + } + } - private LevelListValue(Level[] levels) { - this.levels = levels; - } + private LevelListValue(Level[] levels) { + this.levels = levels; + } - public static LevelListValue valueOf(Array layers, Context context) { - return new LevelListValue(layers, context); - } + public static LevelListValue valueOf(Array layers, Context context) { + return new LevelListValue(layers, context); + } - public static LevelListValue value(Level[] levels) { - return new LevelListValue(levels); - } + public static LevelListValue value(Level[] levels) { + return new LevelListValue(levels); + } - @Override - public void apply(ProteusView view, Context context, ProteusLayoutInflater.ImageLoader loader, Callback callback) { - final LevelListDrawable levelListDrawable = new LevelListDrawable(); - for (Level level : levels) { - level.apply(view, levelListDrawable); - } - } + @Override + public void apply(ProteusView view, Context context, ProteusLayoutInflater.ImageLoader loader, Callback callback) { + final LevelListDrawable levelListDrawable = new LevelListDrawable(); + for (Level level : levels) { + level.apply(view, levelListDrawable); + } + } - public Iterator getLevels() { - return new SimpleArrayIterator<>(levels); - } + public Iterator getLevels() { + return new SimpleArrayIterator<>(levels); + } - public static class Level { - public static final String MIN_LEVEL = "minLevel"; - public static final String MAX_LEVEL = "maxLevel"; - public static final String DRAWABLE = "drawable"; + public static class Level { + public static final String MIN_LEVEL = "minLevel"; + public static final String MAX_LEVEL = "maxLevel"; + public static final String DRAWABLE = "drawable"; - public final int minLevel; - public final int maxLevel; + public final int minLevel; + public final int maxLevel; - @NonNull - public final Value drawable; + @NonNull + public final Value drawable; - Level(ObjectValue value, Context context) { + Level(ObjectValue value, Context context) { - //noinspection ConstantConditions - minLevel = value.getAsInteger(MIN_LEVEL); + //noinspection ConstantConditions + minLevel = value.getAsInteger(MIN_LEVEL); - //noinspection ConstantConditions - maxLevel = value.getAsInteger(MAX_LEVEL); + //noinspection ConstantConditions + maxLevel = value.getAsInteger(MAX_LEVEL); - drawable = DrawableResourceProcessor.staticCompile(value.get(DRAWABLE), context); - } + drawable = DrawableResourceProcessor.staticCompile(value.get(DRAWABLE), context); + } - private Level(int minLevel, int maxLevel, @NonNull Value drawable) { - this.minLevel = minLevel; - this.maxLevel = maxLevel; - this.drawable = drawable; - } + private Level(int minLevel, int maxLevel, @NonNull Value drawable) { + this.minLevel = minLevel; + this.maxLevel = maxLevel; + this.drawable = drawable; + } - @NonNull - public static Level valueOf(int minLevel, int maxLevel, @NonNull Value drawable, Context context) { - return new Level(minLevel, maxLevel, DrawableResourceProcessor.staticCompile(drawable, context)); - } + @NonNull + public static Level valueOf(int minLevel, int maxLevel, @NonNull Value drawable, Context context) { + return new Level(minLevel, maxLevel, DrawableResourceProcessor.staticCompile(drawable, context)); + } - public void apply(ProteusView view, final LevelListDrawable levelListDrawable) { - levelListDrawable.addLevel(minLevel, maxLevel, DrawableResourceProcessor.evaluate(drawable, view)); - } - } + public void apply(ProteusView view, final LevelListDrawable levelListDrawable) { + levelListDrawable.addLevel(minLevel, maxLevel, DrawableResourceProcessor.evaluate(drawable, view)); + } } + } - public static class RippleValue extends DrawableValue { + public static class RippleValue extends DrawableValue { - public static final String COLOR = "color"; - public static final String MASK = "mask"; - public static final String CONTENT = "content"; - public static final String DEFAULT_BACKGROUND = "defaultBackground"; + public static final String COLOR = "color"; + public static final String MASK = "mask"; + public static final String CONTENT = "content"; + public static final String DEFAULT_BACKGROUND = "defaultBackground"; - @NonNull - public final Value color; + @NonNull + public final Value color; - @Nullable - public final Value mask; + @Nullable + public final Value mask; - @Nullable - public final Value content; + @Nullable + public final Value content; - @Nullable - public final Value defaultBackground; + @Nullable + public final Value defaultBackground; - public RippleValue(@NonNull Value color, @Nullable Value mask, @Nullable Value content, @Nullable Value defaultBackground) { - this.color = color; - this.mask = mask; - this.content = content; - this.defaultBackground = defaultBackground; - } + public RippleValue(@NonNull Value color, @Nullable Value mask, @Nullable Value content, @Nullable Value defaultBackground) { + this.color = color; + this.mask = mask; + this.content = content; + this.defaultBackground = defaultBackground; + } - private RippleValue(ObjectValue object, Context context) { - color = object.get(COLOR); - mask = DrawableResourceProcessor.staticCompile(object.get(MASK), context); - content = DrawableResourceProcessor.staticCompile(object.get(CONTENT), context); - defaultBackground = DrawableResourceProcessor.staticCompile(object.get(DEFAULT_BACKGROUND), context); - } + private RippleValue(ObjectValue object, Context context) { + color = object.get(COLOR); + mask = DrawableResourceProcessor.staticCompile(object.get(MASK), context); + content = DrawableResourceProcessor.staticCompile(object.get(CONTENT), context); + defaultBackground = DrawableResourceProcessor.staticCompile(object.get(DEFAULT_BACKGROUND), context); + } - public static RippleValue valueOf(@NonNull Value color, @Nullable Value mask, @Nullable Value content, @Nullable Value defaultBackground) { - return new RippleValue(color, mask, content, defaultBackground); - } + public static RippleValue valueOf(@NonNull Value color, @Nullable Value mask, @Nullable Value content, @Nullable Value defaultBackground) { + return new RippleValue(color, mask, content, defaultBackground); + } - public static RippleValue valueOf(ObjectValue value, Context context) { - return new RippleValue(value, context); - } + public static RippleValue valueOf(ObjectValue value, Context context) { + return new RippleValue(value, context); + } - @Override - public void apply(ProteusView view, Context context, ProteusLayoutInflater.ImageLoader loader, Callback callback) { - ColorStateList colorStateList; - Drawable contentDrawable = null; - Drawable maskDrawable = null; - - Drawable resultDrawable = null; - - Color.Result result = ColorResourceProcessor.evaluate(color, view); - - if (null != result.colors) { - colorStateList = result.colors; - } else { - int[][] states = new int[][]{ - new int[]{} - }; - - int[] colors = new int[]{ - result.color - }; - colorStateList = new ColorStateList(states, colors); - } - - if (null != content) { - contentDrawable = DrawableResourceProcessor.evaluate(content, view); - } - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - if (null != mask) { - maskDrawable = DrawableResourceProcessor.evaluate(mask, view); - } - resultDrawable = new RippleDrawable(colorStateList, contentDrawable, maskDrawable); - } else if (null != defaultBackground) { - resultDrawable = DrawableResourceProcessor.evaluate(defaultBackground, view); - } else if (contentDrawable != null) { - int pressedColor = colorStateList.getColorForState(new int[]{android.R.attr.state_pressed}, colorStateList.getDefaultColor()); - int focusedColor = colorStateList.getColorForState(new int[]{android.R.attr.state_focused}, pressedColor); - ColorDrawable pressedColorDrawable = new ColorDrawable(pressedColor); - ColorDrawable focusedColorDrawable = new ColorDrawable(focusedColor); - StateListDrawable stateListDrawable = new StateListDrawable(); - stateListDrawable.addState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed}, pressedColorDrawable); - stateListDrawable.addState(new int[]{android.R.attr.state_enabled, android.R.attr.state_focused}, focusedColorDrawable); - stateListDrawable.addState(new int[]{android.R.attr.state_enabled}, contentDrawable); - resultDrawable = stateListDrawable; - } - - callback.apply(resultDrawable); - } + @Override + public void apply(ProteusView view, Context context, ProteusLayoutInflater.ImageLoader loader, Callback callback) { + ColorStateList colorStateList; + Drawable contentDrawable = null; + Drawable maskDrawable = null; + + Drawable resultDrawable = null; + + Color.Result result = ColorResourceProcessor.evaluate(color, view); + + if (null != result.colors) { + colorStateList = result.colors; + } else { + int[][] states = new int[][]{ + new int[]{} + }; + + int[] colors = new int[]{ + result.color + }; + colorStateList = new ColorStateList(states, colors); + } + + if (null != content) { + contentDrawable = DrawableResourceProcessor.evaluate(content, view); + } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + if (null != mask) { + maskDrawable = DrawableResourceProcessor.evaluate(mask, view); + } + resultDrawable = new RippleDrawable(colorStateList, contentDrawable, maskDrawable); + } else if (null != defaultBackground) { + resultDrawable = DrawableResourceProcessor.evaluate(defaultBackground, view); + } else if (contentDrawable != null) { + int pressedColor = colorStateList.getColorForState(new int[]{android.R.attr.state_pressed}, colorStateList.getDefaultColor()); + int focusedColor = colorStateList.getColorForState(new int[]{android.R.attr.state_focused}, pressedColor); + ColorDrawable pressedColorDrawable = new ColorDrawable(pressedColor); + ColorDrawable focusedColorDrawable = new ColorDrawable(focusedColor); + StateListDrawable stateListDrawable = new StateListDrawable(); + stateListDrawable.addState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed}, pressedColorDrawable); + stateListDrawable.addState(new int[]{android.R.attr.state_enabled, android.R.attr.state_focused}, focusedColorDrawable); + stateListDrawable.addState(new int[]{android.R.attr.state_enabled}, contentDrawable); + resultDrawable = stateListDrawable; + } + + callback.apply(resultDrawable); } + } - public static class UrlValue extends DrawableValue { + public static class UrlValue extends DrawableValue { - public final String url; + public final String url; - private UrlValue(String url) { - this.url = url; - } + private UrlValue(String url) { + this.url = url; + } - public static UrlValue valueOf(String url) { - return new UrlValue(url); - } + public static UrlValue valueOf(String url) { + return new UrlValue(url); + } + @Override + public void apply(final ProteusView view, Context context, ProteusLayoutInflater.ImageLoader loader, final Callback callback) { + loader.getBitmap(view, url, new AsyncCallback() { @Override - public void apply(final ProteusView view, Context context, ProteusLayoutInflater.ImageLoader loader, final Callback callback) { - loader.getBitmap(view, url, new AsyncCallback() { - @Override - protected void apply(@NonNull Drawable drawable) { - callback.apply(drawable); - } - - @Override - protected void apply(@NonNull Bitmap bitmap) { - callback.apply(convertBitmapToDrawable(bitmap, view.getAsView().getContext())); - } - }); + protected void apply(@NonNull Drawable drawable) { + callback.apply(drawable); } - } - - /** - * - */ - private static abstract class DrawableElement extends Value { - - public abstract void apply(ProteusView view, GradientDrawable drawable); @Override - public Value copy() { - return this; + protected void apply(@NonNull Bitmap bitmap) { + callback.apply(convertBitmapToDrawable(bitmap, view.getAsView().getContext())); } + }); } + } - public static class Gradient extends DrawableElement { + /** + * + */ + private static abstract class DrawableElement extends Value { - public static final String ANGLE = "angle"; - public static final String CENTER_X = "centerX"; - public static final String CENTER_Y = "centerY"; - public static final String CENTER_COLOR = "centerColor"; - public static final String END_COLOR = "endColor"; - public static final String GRADIENT_RADIUS = "gradientRadius"; - public static final String START_COLOR = "startColor"; - public static final String GRADIENT_TYPE = "gradientType"; - public static final String USE_LEVEL = "useLevel"; + public abstract void apply(ProteusView view, GradientDrawable drawable); - private static final int GRADIENT_TYPE_NONE = -1; - - private static final String LINEAR_GRADIENT = "linear"; - private static final String RADIAL_GRADIENT = "radial"; - private static final String SWEEP_GRADIENT = "sweep"; - - @Nullable - public final Integer angle; + @Override + public Value copy() { + return this; + } + } - @Nullable - public final Float centerX; + public static class Gradient extends DrawableElement { - @Nullable - public final Float centerY; + public static final String ANGLE = "angle"; + public static final String CENTER_X = "centerX"; + public static final String CENTER_Y = "centerY"; + public static final String CENTER_COLOR = "centerColor"; + public static final String END_COLOR = "endColor"; + public static final String GRADIENT_RADIUS = "gradientRadius"; + public static final String START_COLOR = "startColor"; + public static final String GRADIENT_TYPE = "gradientType"; + public static final String USE_LEVEL = "useLevel"; - @Nullable - public final Value centerColor; + private static final int GRADIENT_TYPE_NONE = -1; - @Nullable - public final Value endColor; + private static final String LINEAR_GRADIENT = "linear"; + private static final String RADIAL_GRADIENT = "radial"; + private static final String SWEEP_GRADIENT = "sweep"; - @Nullable - public final Value gradientRadius; + @Nullable + public final Integer angle; - @Nullable - public final Value startColor; + @Nullable + public final Float centerX; - public final int gradientType; + @Nullable + public final Float centerY; - @Nullable - public final Boolean useLevel; + @Nullable + public final Value centerColor; - private Gradient(ObjectValue gradient, Context context) { - angle = gradient.getAsInteger(ANGLE); - centerX = gradient.getAsFloat(CENTER_X); - centerY = gradient.getAsFloat(CENTER_Y); + @Nullable + public final Value endColor; - Value value; + @Nullable + public final Value gradientRadius; - value = gradient.get(START_COLOR); - if (value != null) { - startColor = ColorResourceProcessor.staticCompile(value, context); - } else { - startColor = null; - } + @Nullable + public final Value startColor; - value = gradient.get(CENTER_COLOR); - if (value != null) { - centerColor = ColorResourceProcessor.staticCompile(value, context); - } else { - centerColor = null; - } + public final int gradientType; - value = gradient.get(END_COLOR); - if (value != null) { - endColor = ColorResourceProcessor.staticCompile(value, context); - } else { - endColor = null; - } + @Nullable + public final Boolean useLevel; + + private Gradient(ObjectValue gradient, Context context) { + angle = gradient.getAsInteger(ANGLE); + centerX = gradient.getAsFloat(CENTER_X); + centerY = gradient.getAsFloat(CENTER_Y); + + Value value; + + value = gradient.get(START_COLOR); + if (value != null) { + startColor = ColorResourceProcessor.staticCompile(value, context); + } else { + startColor = null; + } + + value = gradient.get(CENTER_COLOR); + if (value != null) { + centerColor = ColorResourceProcessor.staticCompile(value, context); + } else { + centerColor = null; + } + + value = gradient.get(END_COLOR); + if (value != null) { + endColor = ColorResourceProcessor.staticCompile(value, context); + } else { + endColor = null; + } + + value = gradient.get(GRADIENT_RADIUS); + if (value != null) { + gradientRadius = DimensionAttributeProcessor.staticCompile(value, context); + } else { + gradientRadius = null; + } + + gradientType = getGradientType(gradient.getAsString(GRADIENT_TYPE)); + + useLevel = gradient.getAsBoolean(USE_LEVEL); + } - value = gradient.get(GRADIENT_RADIUS); - if (value != null) { - gradientRadius = DimensionAttributeProcessor.staticCompile(value, context); - } else { - gradientRadius = null; - } + public static Gradient valueOf(ObjectValue value, Context context) { + return new Gradient(value, context); + } - gradientType = getGradientType(gradient.getAsString(GRADIENT_TYPE)); + public static GradientDrawable.Orientation getOrientation(@Nullable Integer angle) { + GradientDrawable.Orientation orientation = GradientDrawable.Orientation.LEFT_RIGHT; + if (null != angle) { + angle %= 360; + if (angle % 45 == 0) { + switch (angle) { + case 0: + orientation = GradientDrawable.Orientation.LEFT_RIGHT; + break; + case 45: + orientation = GradientDrawable.Orientation.BL_TR; + break; + case 90: + orientation = GradientDrawable.Orientation.BOTTOM_TOP; + break; + case 135: + orientation = GradientDrawable.Orientation.BR_TL; + break; + case 180: + orientation = GradientDrawable.Orientation.RIGHT_LEFT; + break; + case 225: + orientation = GradientDrawable.Orientation.TR_BL; + break; + case 270: + orientation = GradientDrawable.Orientation.TOP_BOTTOM; + break; + case 315: + orientation = GradientDrawable.Orientation.TL_BR; + break; + } + } + } + return orientation; + } - useLevel = gradient.getAsBoolean(USE_LEVEL); - } + public static GradientDrawable init(@Nullable int[] colors, @Nullable Integer angle) { + return colors != null ? new GradientDrawable(getOrientation(angle), colors) : new GradientDrawable(); + } - public static Gradient valueOf(ObjectValue value, Context context) { - return new Gradient(value, context); - } + @Override + public void apply(ProteusView view, final GradientDrawable drawable) { + if (null != centerX && null != centerY) { + drawable.setGradientCenter(centerX, centerY); + } + + if (null != gradientRadius) { + drawable.setGradientRadius(DimensionAttributeProcessor.evaluate(gradientRadius, view)); + } + + if (GRADIENT_TYPE_NONE != gradientType) { + drawable.setGradientType(gradientType); + } + } - public static GradientDrawable.Orientation getOrientation(@Nullable Integer angle) { - GradientDrawable.Orientation orientation = GradientDrawable.Orientation.LEFT_RIGHT; - if (null != angle) { - angle %= 360; - if (angle % 45 == 0) { - switch (angle) { - case 0: - orientation = GradientDrawable.Orientation.LEFT_RIGHT; - break; - case 45: - orientation = GradientDrawable.Orientation.BL_TR; - break; - case 90: - orientation = GradientDrawable.Orientation.BOTTOM_TOP; - break; - case 135: - orientation = GradientDrawable.Orientation.BR_TL; - break; - case 180: - orientation = GradientDrawable.Orientation.RIGHT_LEFT; - break; - case 225: - orientation = GradientDrawable.Orientation.TR_BL; - break; - case 270: - orientation = GradientDrawable.Orientation.TOP_BOTTOM; - break; - case 315: - orientation = GradientDrawable.Orientation.TL_BR; - break; - } - } - } - return orientation; - } + private int getGradientType(@Nullable String type) { + if (null == type) { + return GRADIENT_TYPE_NONE; + } + switch (type) { + case LINEAR_GRADIENT: + return GradientDrawable.LINEAR_GRADIENT; + case RADIAL_GRADIENT: + return GradientDrawable.RADIAL_GRADIENT; + case SWEEP_GRADIENT: + return GradientDrawable.SWEEP_GRADIENT; + default: + return GRADIENT_TYPE_NONE; + } + } - public static GradientDrawable init(@Nullable int[] colors, @Nullable Integer angle) { - return colors != null ? new GradientDrawable(getOrientation(angle), colors) : new GradientDrawable(); - } + public GradientDrawable init(ProteusView view) { + int[] colors; + if (centerColor != null) { + colors = new int[3]; + colors[0] = ColorResourceProcessor.evaluate(startColor, view).color; + colors[1] = ColorResourceProcessor.evaluate(centerColor, view).color; + colors[2] = ColorResourceProcessor.evaluate(endColor, view).color; + } else { + colors = new int[2]; + colors[0] = ColorResourceProcessor.evaluate(startColor, view).color; + colors[1] = ColorResourceProcessor.evaluate(endColor, view).color; + } + + return init(colors, angle); + } + } - @Override - public void apply(ProteusView view, final GradientDrawable drawable) { - if (null != centerX && null != centerY) { - drawable.setGradientCenter(centerX, centerY); - } - - if (null != gradientRadius) { - drawable.setGradientRadius(DimensionAttributeProcessor.evaluate(gradientRadius, view)); - } - - if (GRADIENT_TYPE_NONE != gradientType) { - drawable.setGradientType(gradientType); - } - } + public static class Corners extends DrawableElement { - private int getGradientType(@Nullable String type) { - if (null == type) { - return GRADIENT_TYPE_NONE; - } - switch (type) { - case LINEAR_GRADIENT: - return GradientDrawable.LINEAR_GRADIENT; - case RADIAL_GRADIENT: - return GradientDrawable.RADIAL_GRADIENT; - case SWEEP_GRADIENT: - return GradientDrawable.SWEEP_GRADIENT; - default: - return GRADIENT_TYPE_NONE; - } - } + public static final String RADIUS = "radius"; + public static final String TOP_LEFT_RADIUS = "topLeftRadius"; + public static final String TOP_RIGHT_RADIUS = "topRightRadius"; + public static final String BOTTOM_LEFT_RADIUS = "bottomLeftRadius"; + public static final String BOTTOM_RIGHT_RADIUS = "bottomRightRadius"; - public GradientDrawable init(ProteusView view) { - int[] colors; - if (centerColor != null) { - colors = new int[3]; - colors[0] = ColorResourceProcessor.evaluate(startColor, view).color; - colors[1] = ColorResourceProcessor.evaluate(centerColor, view).color; - colors[2] = ColorResourceProcessor.evaluate(endColor, view).color; - } else { - colors = new int[2]; - colors[0] = ColorResourceProcessor.evaluate(startColor, view).color; - colors[1] = ColorResourceProcessor.evaluate(endColor, view).color; - } - - return init(colors, angle); - } + @Nullable + private final Value radius; + @Nullable + private final Value topLeftRadius; + @Nullable + private final Value topRightRadius; + @Nullable + private final Value bottomLeftRadius; + @Nullable + private final Value bottomRightRadius; + + private Corners(ObjectValue corner, Context context) { + radius = DimensionAttributeProcessor.staticCompile(corner.get(RADIUS), context); + topLeftRadius = DimensionAttributeProcessor.staticCompile(corner.get(TOP_LEFT_RADIUS), context); + topRightRadius = DimensionAttributeProcessor.staticCompile(corner.get(TOP_RIGHT_RADIUS), context); + bottomLeftRadius = DimensionAttributeProcessor.staticCompile(corner.get(BOTTOM_LEFT_RADIUS), context); + bottomRightRadius = DimensionAttributeProcessor.staticCompile(corner.get(BOTTOM_RIGHT_RADIUS), context); } - public static class Corners extends DrawableElement { - - public static final String RADIUS = "radius"; - public static final String TOP_LEFT_RADIUS = "topLeftRadius"; - public static final String TOP_RIGHT_RADIUS = "topRightRadius"; - public static final String BOTTOM_LEFT_RADIUS = "bottomLeftRadius"; - public static final String BOTTOM_RIGHT_RADIUS = "bottomRightRadius"; - - @Nullable - private final Value radius; - @Nullable - private final Value topLeftRadius; - @Nullable - private final Value topRightRadius; - @Nullable - private final Value bottomLeftRadius; - @Nullable - private final Value bottomRightRadius; - - private Corners(ObjectValue corner, Context context) { - radius = DimensionAttributeProcessor.staticCompile(corner.get(RADIUS), context); - topLeftRadius = DimensionAttributeProcessor.staticCompile(corner.get(TOP_LEFT_RADIUS), context); - topRightRadius = DimensionAttributeProcessor.staticCompile(corner.get(TOP_RIGHT_RADIUS), context); - bottomLeftRadius = DimensionAttributeProcessor.staticCompile(corner.get(BOTTOM_LEFT_RADIUS), context); - bottomRightRadius = DimensionAttributeProcessor.staticCompile(corner.get(BOTTOM_RIGHT_RADIUS), context); - } - - public static Corners valueOf(ObjectValue corner, Context context) { - return new Corners(corner, context); - } + public static Corners valueOf(ObjectValue corner, Context context) { + return new Corners(corner, context); + } - @Override - public void apply(ProteusView view, GradientDrawable gradientDrawable) { - if (null != radius) { - gradientDrawable.setCornerRadius(DimensionAttributeProcessor.evaluate(radius, view)); - } - - float fTopLeftRadius = DimensionAttributeProcessor.evaluate(topLeftRadius, view); - float fTopRightRadius = DimensionAttributeProcessor.evaluate(topRightRadius, view); - float fBottomRightRadius = DimensionAttributeProcessor.evaluate(bottomRightRadius, view); - float fBottomLeftRadius = DimensionAttributeProcessor.evaluate(bottomLeftRadius, view); - - if (fTopLeftRadius != 0 || fTopRightRadius != 0 || fBottomRightRadius != 0 || fBottomLeftRadius != 0) { - // The corner radii are specified in clockwise order (see Path.addRoundRect()) - gradientDrawable.setCornerRadii(new float[]{ - fTopLeftRadius, fTopLeftRadius, - fTopRightRadius, fTopRightRadius, - fBottomRightRadius, fBottomRightRadius, - fBottomLeftRadius, fBottomLeftRadius - }); - } - } + @Override + public void apply(ProteusView view, GradientDrawable gradientDrawable) { + if (null != radius) { + gradientDrawable.setCornerRadius(DimensionAttributeProcessor.evaluate(radius, view)); + } + + float fTopLeftRadius = DimensionAttributeProcessor.evaluate(topLeftRadius, view); + float fTopRightRadius = DimensionAttributeProcessor.evaluate(topRightRadius, view); + float fBottomRightRadius = DimensionAttributeProcessor.evaluate(bottomRightRadius, view); + float fBottomLeftRadius = DimensionAttributeProcessor.evaluate(bottomLeftRadius, view); + + if (fTopLeftRadius != 0 || fTopRightRadius != 0 || fBottomRightRadius != 0 || fBottomLeftRadius != 0) { + // The corner radii are specified in clockwise order (see Path.addRoundRect()) + gradientDrawable.setCornerRadii(new float[]{ + fTopLeftRadius, fTopLeftRadius, + fTopRightRadius, fTopRightRadius, + fBottomRightRadius, fBottomRightRadius, + fBottomLeftRadius, fBottomLeftRadius + }); + } } + } - public static class Solid extends DrawableElement { + public static class Solid extends DrawableElement { - public static final String COLOR = "color"; + public static final String COLOR = "color"; - private final Value color; + private final Value color; - private Solid(ObjectValue value, Context context) { - color = ColorResourceProcessor.staticCompile(value.get(COLOR), context); - } + private Solid(ObjectValue value, Context context) { + color = ColorResourceProcessor.staticCompile(value.get(COLOR), context); + } - public static Solid valueOf(ObjectValue value, Context context) { - return new Solid(value, context); - } + public static Solid valueOf(ObjectValue value, Context context) { + return new Solid(value, context); + } - @Override - public void apply(ProteusView view, final GradientDrawable gradientDrawable) { - Color.Result result = ColorResourceProcessor.evaluate(color, view); - if (null != result.colors && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - gradientDrawable.setColor(result.colors); - } else { - gradientDrawable.setColor(result.color); - } - } + @Override + public void apply(ProteusView view, final GradientDrawable gradientDrawable) { + Color.Result result = ColorResourceProcessor.evaluate(color, view); + if (null != result.colors && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + gradientDrawable.setColor(result.colors); + } else { + gradientDrawable.setColor(result.color); + } } + } - public static class Size extends DrawableElement { + public static class Size extends DrawableElement { - private static final String WIDTH = "width"; - private static final String HEIGHT = "height"; + private static final String WIDTH = "width"; + private static final String HEIGHT = "height"; - private final Value width; - private final Value height; + private final Value width; + private final Value height; - private Size(ObjectValue value, Context context) { - width = DimensionAttributeProcessor.staticCompile(value.get(WIDTH), context); - height = DimensionAttributeProcessor.staticCompile(value.get(HEIGHT), context); - } + private Size(ObjectValue value, Context context) { + width = DimensionAttributeProcessor.staticCompile(value.get(WIDTH), context); + height = DimensionAttributeProcessor.staticCompile(value.get(HEIGHT), context); + } - public static Size valueOf(ObjectValue value, Context context) { - return new Size(value, context); - } + public static Size valueOf(ObjectValue value, Context context) { + return new Size(value, context); + } - @Override - public void apply(ProteusView view, GradientDrawable gradientDrawable) { - gradientDrawable.setSize((int) DimensionAttributeProcessor.evaluate(width, view), (int) DimensionAttributeProcessor.evaluate(height, view)); - } + @Override + public void apply(ProteusView view, GradientDrawable gradientDrawable) { + gradientDrawable.setSize((int) DimensionAttributeProcessor.evaluate(width, view), (int) DimensionAttributeProcessor.evaluate(height, view)); } + } - public static class Stroke extends DrawableElement { + public static class Stroke extends DrawableElement { - public static final String WIDTH = "width"; - public static final String COLOR = "color"; - public static final String DASH_WIDTH = "dashWidth"; - public static final String DASH_GAP = "dashGap"; + public static final String WIDTH = "width"; + public static final String COLOR = "color"; + public static final String DASH_WIDTH = "dashWidth"; + public static final String DASH_GAP = "dashGap"; - public final Value width; - public final Value color; - public final Value dashWidth; - public final Value dashGap; + public final Value width; + public final Value color; + public final Value dashWidth; + public final Value dashGap; - private Stroke(ObjectValue stroke, Context context) { - width = DimensionAttributeProcessor.staticCompile(stroke.get(WIDTH), context); - color = ColorResourceProcessor.staticCompile(stroke.get(COLOR), context); - dashWidth = DimensionAttributeProcessor.staticCompile(stroke.get(DASH_WIDTH), context); - dashGap = DimensionAttributeProcessor.staticCompile(stroke.get(DASH_GAP), context); - } + private Stroke(ObjectValue stroke, Context context) { + width = DimensionAttributeProcessor.staticCompile(stroke.get(WIDTH), context); + color = ColorResourceProcessor.staticCompile(stroke.get(COLOR), context); + dashWidth = DimensionAttributeProcessor.staticCompile(stroke.get(DASH_WIDTH), context); + dashGap = DimensionAttributeProcessor.staticCompile(stroke.get(DASH_GAP), context); + } - public static Stroke valueOf(ObjectValue stroke, Context context) { - return new Stroke(stroke, context); - } + public static Stroke valueOf(ObjectValue stroke, Context context) { + return new Stroke(stroke, context); + } - @Override - public void apply(ProteusView view, GradientDrawable gradientDrawable) { - if (null == dashWidth) { - gradientDrawable.setStroke((int) DimensionAttributeProcessor.evaluate(width, view), ColorResourceProcessor.evaluate(color, view).color); - } else if (null != dashGap) { - gradientDrawable.setStroke((int) DimensionAttributeProcessor.evaluate(width, view), - ColorResourceProcessor.evaluate(color, view).color, - DimensionAttributeProcessor.evaluate(dashWidth, view), - DimensionAttributeProcessor.evaluate(dashGap, view)); - } - } + @Override + public void apply(ProteusView view, GradientDrawable gradientDrawable) { + if (null == dashWidth) { + gradientDrawable.setStroke((int) DimensionAttributeProcessor.evaluate(width, view), ColorResourceProcessor.evaluate(color, view).color); + } else if (null != dashGap) { + gradientDrawable.setStroke((int) DimensionAttributeProcessor.evaluate(width, view), + ColorResourceProcessor.evaluate(color, view).color, + DimensionAttributeProcessor.evaluate(dashWidth, view), + DimensionAttributeProcessor.evaluate(dashGap, view)); + } } + } - /** - * AsyncCallback - * - * @author aditya.sharat - */ - public abstract static class AsyncCallback { + /** + * AsyncCallback + * + * @author aditya.sharat + */ + public abstract static class AsyncCallback { - private boolean recycled; + private boolean recycled; - protected AsyncCallback() { - } + protected AsyncCallback() { + } - public void setBitmap(@NonNull Bitmap bitmap) { - if (recycled) { - throw new ProteusInflateException("Cannot make calls to a recycled instance!"); - } - apply(bitmap); - recycled = true; - } + public void setBitmap(@NonNull Bitmap bitmap) { + if (recycled) { + throw new ProteusInflateException("Cannot make calls to a recycled instance!"); + } + apply(bitmap); + recycled = true; + } - public void setDrawable(@NonNull Drawable drawable) { - if (recycled) { - throw new ProteusInflateException("Cannot make calls to a recycled instance!"); - } - apply(drawable); - recycled = true; - } + public void setDrawable(@NonNull Drawable drawable) { + if (recycled) { + throw new ProteusInflateException("Cannot make calls to a recycled instance!"); + } + apply(drawable); + recycled = true; + } - protected abstract void apply(@NonNull Drawable drawable); + protected abstract void apply(@NonNull Drawable drawable); - protected abstract void apply(@NonNull Bitmap bitmap); - } + protected abstract void apply(@NonNull Bitmap bitmap); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Layout.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Layout.java index 4e194eba..89d09fd6 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Layout.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Layout.java @@ -34,94 +34,94 @@ public class Layout extends Value { - @NonNull - public final String type; - - @Nullable - public final List attributes; + @NonNull + public final String type; + + @Nullable + public final List attributes; + + @Nullable + public final Map data; + + @Nullable + public final ObjectValue extras; + + public Layout(@NonNull String type, @Nullable List attributes, @Nullable Map data, @Nullable ObjectValue extras) { + this.type = type; + this.attributes = attributes; + this.data = data; + this.extras = extras; + } + + @Override + public Layout copy() { + List attributes = null; + if (this.attributes != null) { + attributes = new ArrayList<>(this.attributes.size()); + for (Attribute attribute : this.attributes) { + attributes.add(attribute.copy()); + } + } - @Nullable - public final Map data; + return new Layout(type, attributes, data, extras); + } - @Nullable - public final ObjectValue extras; + public Layout merge(Layout include) { - public Layout(@NonNull String type, @Nullable List attributes, @Nullable Map data, @Nullable ObjectValue extras) { - this.type = type; - this.attributes = attributes; - this.data = data; - this.extras = extras; + List attributes = null; + if (this.attributes != null) { + attributes = new ArrayList<>(this.attributes.size()); + attributes.addAll(this.attributes); + } + if (include.attributes != null) { + if (attributes == null) { + attributes = new ArrayList<>(include.attributes.size()); + } + attributes.addAll(include.attributes); } - @Override - public Layout copy() { - List attributes = null; - if (this.attributes != null) { - attributes = new ArrayList<>(this.attributes.size()); - for (Attribute attribute : this.attributes) { - attributes.add(attribute.copy()); - } - } - - return new Layout(type, attributes, data, extras); + Map data = null; + if (this.data != null) { + data = this.data; + } + if (include.data != null) { + if (data == null) { + data = new LinkedHashMap<>(include.data.size()); + } + data.putAll(include.data); } - public Layout merge(Layout include) { - - List attributes = null; - if (this.attributes != null) { - attributes = new ArrayList<>(this.attributes.size()); - attributes.addAll(this.attributes); - } - if (include.attributes != null) { - if (attributes == null) { - attributes = new ArrayList<>(include.attributes.size()); - } - attributes.addAll(include.attributes); - } - - Map data = null; - if (this.data != null) { - data = this.data; - } - if (include.data != null) { - if (data == null) { - data = new LinkedHashMap<>(include.data.size()); - } - data.putAll(include.data); - } - - ObjectValue extras = new ObjectValue(); - if (this.extras != null) { - extras = Utils.addAllEntries(extras, this.extras); - } - if (include.extras != null) { - if (extras == null) { - extras = new ObjectValue(); - } - Utils.addAllEntries(extras, include.extras); - } - - return new Layout(type, attributes, data, extras); + ObjectValue extras = new ObjectValue(); + if (this.extras != null) { + extras = Utils.addAllEntries(extras, this.extras); } + if (include.extras != null) { + if (extras == null) { + extras = new ObjectValue(); + } + Utils.addAllEntries(extras, include.extras); + } + + return new Layout(type, attributes, data, extras); + } - /** - * Attribute - * - * @author aditya.sharat - */ - public static class Attribute { + /** + * Attribute + * + * @author aditya.sharat + */ + public static class Attribute { - public final int id; - public final Value value; + public final int id; + public final Value value; - public Attribute(int id, Value value) { - this.id = id; - this.value = value; - } + public Attribute(int id, Value value) { + this.id = id; + this.value = value; + } - protected Attribute copy() { - return new Attribute(id, value.copy()); - } + protected Attribute copy() { + return new Attribute(id, value.copy()); } + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/NestedBinding.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/NestedBinding.java index 3c133c88..b6f51449 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/NestedBinding.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/NestedBinding.java @@ -30,80 +30,80 @@ public class NestedBinding extends Binding { - public static final String NESTED_BINDING_KEY = "@"; - - private final Value value; - - private NestedBinding(Value value) { - this.value = value; - } - - /** - * @param value - * @return - */ - @NonNull - public static NestedBinding valueOf(@NonNull final Value value) { - return new NestedBinding(value); + public static final String NESTED_BINDING_KEY = "@"; + + private final Value value; + + private NestedBinding(Value value) { + this.value = value; + } + + /** + * @param value + * @return + */ + @NonNull + public static NestedBinding valueOf(@NonNull final Value value) { + return new NestedBinding(value); + } + + @NonNull + public Value getValue() { + return value; + } + + @NonNull + @Override + public Value evaluate(Context context, Value data, int index) { + return evaluate(context, value, data, index); + } + + @NonNull + @Override + public String toString() { + return getClass().getName() + "@" + Integer.toHexString(hashCode()); + } + + private Value evaluate(Context context, Binding binding, Value data, int index) { + return binding.getAsBinding().evaluate(context, data, index); + } + + private Value evaluate(Context context, ObjectValue object, Value data, int index) { + ObjectValue evaluated = new ObjectValue(); + String key; + Value value; + for (Map.Entry entry : object.entrySet()) { + key = entry.getKey(); + value = evaluate(context, entry.getValue(), data, index); + evaluated.add(key, value); } - @NonNull - public Value getValue() { - return value; - } - - @NonNull - @Override - public Value evaluate(Context context, Value data, int index) { - return evaluate(context, value, data, index); - } + return evaluated; + } - @NonNull - @Override - public String toString() { - return getClass().getName() + "@" + Integer.toHexString(hashCode()); + private Value evaluate(Context context, Array array, Value data, int index) { + Array evaluated = new Array(array.size()); + Iterator iterator = array.iterator(); + while (iterator.hasNext()) { + evaluated.add(evaluate(context, iterator.next(), data, index)); } - - private Value evaluate(Context context, Binding binding, Value data, int index) { - return binding.getAsBinding().evaluate(context, data, index); + return evaluated; + } + + private Value evaluate(Context context, Value value, Value data, int index) { + Value evaluated = value; + if (value.isBinding()) { + evaluated = evaluate(context, value.getAsBinding(), data, index); + } else if (value.isObject()) { + evaluated = evaluate(context, value.getAsObject(), data, index); + } else if (value.isArray()) { + evaluated = evaluate(context, value.getAsArray(), data, index); } + return evaluated; + } - private Value evaluate(Context context, ObjectValue object, Value data, int index) { - ObjectValue evaluated = new ObjectValue(); - String key; - Value value; - for (Map.Entry entry : object.entrySet()) { - key = entry.getKey(); - value = evaluate(context, entry.getValue(), data, index); - evaluated.add(key, value); - } - - return evaluated; - } - - private Value evaluate(Context context, Array array, Value data, int index) { - Array evaluated = new Array(array.size()); - Iterator iterator = array.iterator(); - while (iterator.hasNext()) { - evaluated.add(evaluate(context, iterator.next(), data, index)); - } - return evaluated; - } - - private Value evaluate(Context context, Value value, Value data, int index) { - Value evaluated = value; - if (value.isBinding()) { - evaluated = evaluate(context, value.getAsBinding(), data, index); - } else if (value.isObject()) { - evaluated = evaluate(context, value.getAsObject(), data, index); - } else if (value.isArray()) { - evaluated = evaluate(context, value.getAsArray(), data, index); - } - return evaluated; - } - - @Override - public Binding copy() { - return this; - } + @Override + public Binding copy() { + return this; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Null.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Null.java index 2f38089b..2cbec1b5 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Null.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Null.java @@ -25,44 +25,44 @@ */ public class Null extends Value { - /** - * singleton for JsonNull - * - * @since 1.8 - */ - public static final Null INSTANCE = new Null(); + /** + * singleton for JsonNull + * + * @since 1.8 + */ + public static final Null INSTANCE = new Null(); - private static final String NULL_STRING = "NULL"; + private static final String NULL_STRING = "NULL"; - @Override - public Null copy() { - return INSTANCE; - } + @Override + public Null copy() { + return INSTANCE; + } - @Override - public String toString() { - return NULL_STRING; - } + @Override + public String toString() { + return NULL_STRING; + } - @Override - public String getAsString() { - return ProteusConstants.EMPTY; - } + @Override + public String getAsString() { + return ProteusConstants.EMPTY; + } - /** - * All instances of Null have the same hash code - * since they are indistinguishable - */ - @Override - public int hashCode() { - return Null.class.hashCode(); - } + /** + * All instances of Null have the same hash code + * since they are indistinguishable + */ + @Override + public int hashCode() { + return Null.class.hashCode(); + } - /** - * All instances of JsonNull are the same - */ - @Override - public boolean equals(java.lang.Object other) { - return this == other || other instanceof Null; - } + /** + * All instances of JsonNull are the same + */ + @Override + public boolean equals(java.lang.Object other) { + return this == other || other instanceof Null; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/ObjectValue.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/ObjectValue.java index 281eb1d0..c887483e 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/ObjectValue.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/ObjectValue.java @@ -30,315 +30,315 @@ public class ObjectValue extends Value { - private final HashMap members = new HashMap<>(); - - @Override - public ObjectValue copy() { - ObjectValue result = new ObjectValue(); - for (Map.Entry entry : members.entrySet()) { - result.add(entry.getKey(), entry.getValue().copy()); - } - return result; - } - - /** - * Adds a member, which is a name-value pair, to self. The name must be a String, but the value - * can be an arbitrary Value, thereby allowing you to inflate a full tree of Value - * rooted at this node. - * - * @param property name of the member. - * @param value the member object. - */ - public void add(String property, Value value) { - if (value == null) { - value = Null.INSTANCE; - } - members.put(property, value); - } - - /** - * Removes the {@code property} from this {@link ObjectValue}. - * - * @param property name of the member that should be removed. - * @return the {@link Value} object that is being removed. - * @since 1.3 - */ - public Value remove(String property) { - return members.remove(property); - } - - /** - * Convenience method to add a primitive member. The specified value is converted to a - * Primitive of String. - * - * @param property name of the member. - * @param value the string value associated with the member. - */ - public void addProperty(String property, String value) { - add(property, createValue(value)); - } - - /** - * Convenience method to add a primitive member. The specified value is converted to a - * Primitive of Number. - * - * @param property name of the member. - * @param value the number value associated with the member. - */ - public void addProperty(String property, Number value) { - add(property, createValue(value)); - } - - /** - * Convenience method to add a boolean member. The specified value is converted to a - * Primitive of Boolean. - * - * @param property name of the member. - * @param value the number value associated with the member. - */ - public void addProperty(String property, Boolean value) { - add(property, createValue(value)); - } - - /** - * Convenience method to add a char member. The specified value is converted to a - * Primitive of Character. - * - * @param property name of the member. - * @param value the number value associated with the member. - */ - public void addProperty(String property, Character value) { - add(property, createValue(value)); - } - - /** - * Creates the proper {@link Value} object from the given {@code value} object. - * - * @param value the object to generate the {@link Value} for - * @return a {@link Value} if the {@code value} is not null, otherwise a {@link Null} - */ - private Value createValue(java.lang.Object value) { - return value == null ? Null.INSTANCE : new Primitive(value); - } - - /** - * Returns a set of members of this object. The set is ordered, and the order is in which the - * values were added. - * - * @return a set of members of this object. - */ - public Set> entrySet() { - return members.entrySet(); - } - - /** - * Returns the number of key/value pairs in the object. - * - * @return the number of key/value pairs in the object. - */ - public int size() { - return members.size(); - } - - /** - * Convenience method to check if a member with the specified name is present in this object. - * - * @param memberName name of the member that is being checked for presence. - * @return true if there is a member with the specified name, false otherwise. - */ - public boolean has(String memberName) { - return members.containsKey(memberName); - } - - public boolean isPrimitive(String memberName) { - return has(memberName) && get(memberName).isPrimitive(); - } - - public boolean isBoolean(String memberName) { - if (has(memberName) && get(memberName).isPrimitive()) { - return getAsPrimitive(memberName).isBoolean(); - } - return false; - } - - public boolean isNumber(String memberName) { - if (has(memberName) && get(memberName).isPrimitive()) { - return getAsPrimitive(memberName).isNumber(); - } - return false; - } - - public boolean isObject(String memberName) { - return has(memberName) && get(memberName).isObject(); - } - - public boolean isArray(String memberName) { - return has(memberName) && get(memberName).isArray(); - } - - public boolean isNull(String memberName) { - return has(memberName) && get(memberName).isNull(); - } - - public boolean isLayout(String memberName) { - return has(memberName) && get(memberName).isLayout(); - } - - public boolean isBinding(String memberName) { - return has(memberName) && get(memberName).isBinding(); - } - - /** - * Returns the member with the specified name. - * - * @param memberName name of the member that is being requested. - * @return the member matching the name. Null if no such member exists. - */ - public Value get(String memberName) { - return members.get(memberName); - } - - /** - * Convenience method to get the specified member as a Value. - * - * @param memberName name of the member being requested. - * @return the Primitive corresponding to the specified member. - */ - public Primitive getAsPrimitive(String memberName) { - return (Primitive) members.get(memberName); - } - - @Nullable - public Boolean getAsBoolean(String memberName) { - if (isBoolean(memberName)) { - return getAsPrimitive(memberName).getAsBoolean(); - } - return null; - } - - public boolean getAsBoolean(String memberName, boolean defaultValue) { - if (isBoolean(memberName)) { - return getAsPrimitive(memberName).getAsBoolean(); - } - return defaultValue; - } - - @Nullable - public Integer getAsInteger(String memberName) { - if (isNumber(memberName)) { - return getAsPrimitive(memberName).getAsInt(); - } - return null; - } - - public int getAsInteger(String memberName, int defaultValue) { - if (isNumber(memberName)) { - return getAsPrimitive(memberName).getAsInt(); - } - return defaultValue; - } - - @Nullable - public Float getAsFloat(String memberName) { - if (isNumber(memberName)) { - return getAsPrimitive(memberName).getAsFloat(); - } - return null; - } - - public float getAsFloat(String memberName, float defaultValue) { - if (isNumber(memberName)) { - return getAsPrimitive(memberName).getAsFloat(); - } - return defaultValue; - } - - @Nullable - public Double getAsDouble(String memberName) { - if (isNumber(memberName)) { - return getAsPrimitive(memberName).getAsDouble(); - } - return null; - } - - public double getAsDouble(String memberName, double defaultValue) { - if (isNumber(memberName)) { - return getAsPrimitive(memberName).getAsDouble(); - } - return defaultValue; - } - - @Nullable - public Long getAsLong(String memberName) { - if (isNumber(memberName)) { - return getAsPrimitive(memberName).getAsLong(); - } - return null; - } - - public long getAsLong(String memberName, long defaultValue) { - if (isNumber(memberName)) { - return getAsPrimitive(memberName).getAsLong(); - } - return defaultValue; - } - - @Nullable - public String getAsString(String memberName) { - if (isPrimitive(memberName)) { - return getAsPrimitive(memberName).getAsString(); - } - return null; - } - - /** - * Convenience method to get the specified member as a Array. - * - * @param memberName name of the member being requested. - * @return the Array corresponding to the specified member. - */ - public Array getAsArray(String memberName) { - return (Array) members.get(memberName); - } - - /** - * Convenience method to get the specified member as a ObjectValue. - * - * @param memberName name of the member being requested. - * @return the ObjectValue corresponding to the specified member. - */ - @Nullable - public ObjectValue getAsObject(String memberName) { - if (isObject(memberName)) { - return (ObjectValue) members.get(memberName); - } - return null; - } - - @Nullable - public Layout getAsLayout(String memberName) { - if (isLayout(memberName)) { - return (Layout) members.get(memberName); - } - return null; - } - - @Nullable - public Binding getAsBinding(String memberName) { - if (isBinding(memberName)) { - return (Binding) members.get(memberName); - } - return null; - } - - @Override - public boolean equals(java.lang.Object o) { - return (o == this) || (o instanceof ObjectValue && ((ObjectValue) o).members.equals(members)); - } - - @Override - public int hashCode() { - return members.hashCode(); - } + private final HashMap members = new HashMap<>(); + + @Override + public ObjectValue copy() { + ObjectValue result = new ObjectValue(); + for (Map.Entry entry : members.entrySet()) { + result.add(entry.getKey(), entry.getValue().copy()); + } + return result; + } + + /** + * Adds a member, which is a name-value pair, to self. The name must be a String, but the value + * can be an arbitrary Value, thereby allowing you to inflate a full tree of Value + * rooted at this node. + * + * @param property name of the member. + * @param value the member object. + */ + public void add(String property, Value value) { + if (value == null) { + value = Null.INSTANCE; + } + members.put(property, value); + } + + /** + * Removes the {@code property} from this {@link ObjectValue}. + * + * @param property name of the member that should be removed. + * @return the {@link Value} object that is being removed. + * @since 1.3 + */ + public Value remove(String property) { + return members.remove(property); + } + + /** + * Convenience method to add a primitive member. The specified value is converted to a + * Primitive of String. + * + * @param property name of the member. + * @param value the string value associated with the member. + */ + public void addProperty(String property, String value) { + add(property, createValue(value)); + } + + /** + * Convenience method to add a primitive member. The specified value is converted to a + * Primitive of Number. + * + * @param property name of the member. + * @param value the number value associated with the member. + */ + public void addProperty(String property, Number value) { + add(property, createValue(value)); + } + + /** + * Convenience method to add a boolean member. The specified value is converted to a + * Primitive of Boolean. + * + * @param property name of the member. + * @param value the number value associated with the member. + */ + public void addProperty(String property, Boolean value) { + add(property, createValue(value)); + } + + /** + * Convenience method to add a char member. The specified value is converted to a + * Primitive of Character. + * + * @param property name of the member. + * @param value the number value associated with the member. + */ + public void addProperty(String property, Character value) { + add(property, createValue(value)); + } + + /** + * Creates the proper {@link Value} object from the given {@code value} object. + * + * @param value the object to generate the {@link Value} for + * @return a {@link Value} if the {@code value} is not null, otherwise a {@link Null} + */ + private Value createValue(java.lang.Object value) { + return value == null ? Null.INSTANCE : new Primitive(value); + } + + /** + * Returns a set of members of this object. The set is ordered, and the order is in which the + * values were added. + * + * @return a set of members of this object. + */ + public Set> entrySet() { + return members.entrySet(); + } + + /** + * Returns the number of key/value pairs in the object. + * + * @return the number of key/value pairs in the object. + */ + public int size() { + return members.size(); + } + + /** + * Convenience method to check if a member with the specified name is present in this object. + * + * @param memberName name of the member that is being checked for presence. + * @return true if there is a member with the specified name, false otherwise. + */ + public boolean has(String memberName) { + return members.containsKey(memberName); + } + + public boolean isPrimitive(String memberName) { + return has(memberName) && get(memberName).isPrimitive(); + } + + public boolean isBoolean(String memberName) { + if (has(memberName) && get(memberName).isPrimitive()) { + return getAsPrimitive(memberName).isBoolean(); + } + return false; + } + + public boolean isNumber(String memberName) { + if (has(memberName) && get(memberName).isPrimitive()) { + return getAsPrimitive(memberName).isNumber(); + } + return false; + } + + public boolean isObject(String memberName) { + return has(memberName) && get(memberName).isObject(); + } + + public boolean isArray(String memberName) { + return has(memberName) && get(memberName).isArray(); + } + + public boolean isNull(String memberName) { + return has(memberName) && get(memberName).isNull(); + } + + public boolean isLayout(String memberName) { + return has(memberName) && get(memberName).isLayout(); + } + + public boolean isBinding(String memberName) { + return has(memberName) && get(memberName).isBinding(); + } + + /** + * Returns the member with the specified name. + * + * @param memberName name of the member that is being requested. + * @return the member matching the name. Null if no such member exists. + */ + public Value get(String memberName) { + return members.get(memberName); + } + + /** + * Convenience method to get the specified member as a Value. + * + * @param memberName name of the member being requested. + * @return the Primitive corresponding to the specified member. + */ + public Primitive getAsPrimitive(String memberName) { + return (Primitive) members.get(memberName); + } + + @Nullable + public Boolean getAsBoolean(String memberName) { + if (isBoolean(memberName)) { + return getAsPrimitive(memberName).getAsBoolean(); + } + return null; + } + + public boolean getAsBoolean(String memberName, boolean defaultValue) { + if (isBoolean(memberName)) { + return getAsPrimitive(memberName).getAsBoolean(); + } + return defaultValue; + } + + @Nullable + public Integer getAsInteger(String memberName) { + if (isNumber(memberName)) { + return getAsPrimitive(memberName).getAsInt(); + } + return null; + } + + public int getAsInteger(String memberName, int defaultValue) { + if (isNumber(memberName)) { + return getAsPrimitive(memberName).getAsInt(); + } + return defaultValue; + } + + @Nullable + public Float getAsFloat(String memberName) { + if (isNumber(memberName)) { + return getAsPrimitive(memberName).getAsFloat(); + } + return null; + } + + public float getAsFloat(String memberName, float defaultValue) { + if (isNumber(memberName)) { + return getAsPrimitive(memberName).getAsFloat(); + } + return defaultValue; + } + + @Nullable + public Double getAsDouble(String memberName) { + if (isNumber(memberName)) { + return getAsPrimitive(memberName).getAsDouble(); + } + return null; + } + + public double getAsDouble(String memberName, double defaultValue) { + if (isNumber(memberName)) { + return getAsPrimitive(memberName).getAsDouble(); + } + return defaultValue; + } + + @Nullable + public Long getAsLong(String memberName) { + if (isNumber(memberName)) { + return getAsPrimitive(memberName).getAsLong(); + } + return null; + } + + public long getAsLong(String memberName, long defaultValue) { + if (isNumber(memberName)) { + return getAsPrimitive(memberName).getAsLong(); + } + return defaultValue; + } + + @Nullable + public String getAsString(String memberName) { + if (isPrimitive(memberName)) { + return getAsPrimitive(memberName).getAsString(); + } + return null; + } + + /** + * Convenience method to get the specified member as a Array. + * + * @param memberName name of the member being requested. + * @return the Array corresponding to the specified member. + */ + public Array getAsArray(String memberName) { + return (Array) members.get(memberName); + } + + /** + * Convenience method to get the specified member as a ObjectValue. + * + * @param memberName name of the member being requested. + * @return the ObjectValue corresponding to the specified member. + */ + @Nullable + public ObjectValue getAsObject(String memberName) { + if (isObject(memberName)) { + return (ObjectValue) members.get(memberName); + } + return null; + } + + @Nullable + public Layout getAsLayout(String memberName) { + if (isLayout(memberName)) { + return (Layout) members.get(memberName); + } + return null; + } + + @Nullable + public Binding getAsBinding(String memberName) { + if (isBinding(memberName)) { + return (Binding) members.get(memberName); + } + return null; + } + + @Override + public boolean equals(java.lang.Object o) { + return (o == this) || (o instanceof ObjectValue && ((ObjectValue) o).members.equals(members)); + } + + @Override + public int hashCode() { + return members.hashCode(); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Primitive.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Primitive.java index 879f6ac9..3bd89bb3 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Primitive.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Primitive.java @@ -28,279 +28,279 @@ public class Primitive extends Value { - private static final Class[] PRIMITIVE_TYPES = {int.class, long.class, short.class, - float.class, double.class, byte.class, boolean.class, char.class, Integer.class, Long.class, - Short.class, Float.class, Double.class, Byte.class, Boolean.class, Character.class}; - - private java.lang.Object value; - - /** - * Create a primitive containing a boolean value. - * - * @param bool the value to create the primitive with. - */ - public Primitive(Boolean bool) { - setValue(bool); + private static final Class[] PRIMITIVE_TYPES = {int.class, long.class, short.class, + float.class, double.class, byte.class, boolean.class, char.class, Integer.class, Long.class, + Short.class, Float.class, Double.class, Byte.class, Boolean.class, Character.class}; + + private java.lang.Object value; + + /** + * Create a primitive containing a boolean value. + * + * @param bool the value to create the primitive with. + */ + public Primitive(Boolean bool) { + setValue(bool); + } + + /** + * Create a primitive containing a {@link Number}. + * + * @param number the value to create the primitive with. + */ + public Primitive(Number number) { + setValue(number); + } + + /** + * Create a primitive containing a String value. + * + * @param string the value to create the primitive with. + */ + public Primitive(String string) { + setValue(string); + } + + /** + * Create a primitive containing a character. The character is turned into a one character String. + * + * @param c the value to create the primitive with. + */ + public Primitive(Character c) { + setValue(c); + } + + /** + * Create a primitive using the specified ObjectValue. It must be an instance of {@link Number}, a + * Java primitive type, or a String. + * + * @param primitive the value to create the primitive with. + */ + Primitive(java.lang.Object primitive) { + setValue(primitive); + } + + static boolean isPrimitiveOrString(java.lang.Object target) { + if (target instanceof String) { + return true; } - /** - * Create a primitive containing a {@link Number}. - * - * @param number the value to create the primitive with. - */ - public Primitive(Number number) { - setValue(number); + Class classOfPrimitive = target.getClass(); + for (Class standardPrimitive : PRIMITIVE_TYPES) { + if (standardPrimitive.isAssignableFrom(classOfPrimitive)) { + return true; + } } - - /** - * Create a primitive containing a String value. - * - * @param string the value to create the primitive with. - */ - public Primitive(String string) { - setValue(string); - } - - /** - * Create a primitive containing a character. The character is turned into a one character String. - * - * @param c the value to create the primitive with. - */ - public Primitive(Character c) { - setValue(c); - } - - /** - * Create a primitive using the specified ObjectValue. It must be an instance of {@link Number}, a - * Java primitive type, or a String. - * - * @param primitive the value to create the primitive with. - */ - Primitive(java.lang.Object primitive) { - setValue(primitive); - } - - static boolean isPrimitiveOrString(java.lang.Object target) { - if (target instanceof String) { - return true; - } - - Class classOfPrimitive = target.getClass(); - for (Class standardPrimitive : PRIMITIVE_TYPES) { - if (standardPrimitive.isAssignableFrom(classOfPrimitive)) { - return true; - } - } - return false; - } - - /** - * Returns true if the specified number is an integral type - * (Long, Integer, Short, Byte, BigInteger) - */ - private static boolean isIntegral(Primitive primitive) { - if (primitive.value instanceof Number) { - Number number = (Number) primitive.value; - return number instanceof BigInteger || number instanceof Long || number instanceof Integer || number instanceof Short || number instanceof Byte; - } - return false; - } - - @Override - public Primitive copy() { - return this; - } - - void setValue(java.lang.Object primitive) { - if (primitive instanceof Character) { - char c = (Character) primitive; - this.value = String.valueOf(c); - } else { - if (!(primitive instanceof Number || isPrimitiveOrString(primitive))) { - throw new IllegalArgumentException(); - } - this.value = primitive; - } - } - - /** - * Check whether this primitive contains a boolean value. - * - * @return true if this primitive contains a boolean value, false otherwise. - */ - public boolean isBoolean() { - return value instanceof Boolean; - } - - /** - * convenience method to get this value as a {@link Boolean}. - * - * @return get this value as a {@link Boolean}. - */ - Boolean getAsBooleanWrapper() { - return (Boolean) value; - } - - /** - * convenience method to get this value as a boolean value. - * - * @return get this value as a primitive boolean value. - */ - @Override - public boolean getAsBoolean() { - if (isBoolean()) { - return getAsBooleanWrapper(); - } else { - // Check to see if the value as a String is "true" in any case. - return Boolean.parseBoolean(getAsString()); - } + return false; + } + + /** + * Returns true if the specified number is an integral type + * (Long, Integer, Short, Byte, BigInteger) + */ + private static boolean isIntegral(Primitive primitive) { + if (primitive.value instanceof Number) { + Number number = (Number) primitive.value; + return number instanceof BigInteger || number instanceof Long || number instanceof Integer || number instanceof Short || number instanceof Byte; } - - /** - * Check whether this primitive contains a Number. - * - * @return true if this primitive contains a Number, false otherwise. - */ - public boolean isNumber() { - return value instanceof Number; + return false; + } + + @Override + public Primitive copy() { + return this; + } + + void setValue(java.lang.Object primitive) { + if (primitive instanceof Character) { + char c = (Character) primitive; + this.value = String.valueOf(c); + } else { + if (!(primitive instanceof Number || isPrimitiveOrString(primitive))) { + throw new IllegalArgumentException(); + } + this.value = primitive; } - - /** - * convenience method to get this value as a Number. - * - * @return get this value as a Number. - * @throws NumberFormatException if the value contained is not a valid Number. - */ - public Number getAsNumber() { - return value instanceof String ? new LazilyParsedNumber((String) value) : (Number) value; + } + + /** + * Check whether this primitive contains a boolean value. + * + * @return true if this primitive contains a boolean value, false otherwise. + */ + public boolean isBoolean() { + return value instanceof Boolean; + } + + /** + * convenience method to get this value as a {@link Boolean}. + * + * @return get this value as a {@link Boolean}. + */ + Boolean getAsBooleanWrapper() { + return (Boolean) value; + } + + /** + * convenience method to get this value as a boolean value. + * + * @return get this value as a primitive boolean value. + */ + @Override + public boolean getAsBoolean() { + if (isBoolean()) { + return getAsBooleanWrapper(); + } else { + // Check to see if the value as a String is "true" in any case. + return Boolean.parseBoolean(getAsString()); } - - /** - * Check whether this primitive contains a String value. - * - * @return true if this primitive contains a String value, false otherwise. - */ - public boolean isString() { - return value instanceof String; + } + + /** + * Check whether this primitive contains a Number. + * + * @return true if this primitive contains a Number, false otherwise. + */ + public boolean isNumber() { + return value instanceof Number; + } + + /** + * convenience method to get this value as a Number. + * + * @return get this value as a Number. + * @throws NumberFormatException if the value contained is not a valid Number. + */ + public Number getAsNumber() { + return value instanceof String ? new LazilyParsedNumber((String) value) : (Number) value; + } + + /** + * Check whether this primitive contains a String value. + * + * @return true if this primitive contains a String value, false otherwise. + */ + public boolean isString() { + return value instanceof String; + } + + /** + * convenience method to get this value as a String. + * + * @return get this value as a String. + */ + @Override + public String getAsString() { + if (isNumber()) { + return getAsNumber().toString(); + } else if (isBoolean()) { + return getAsBooleanWrapper().toString(); + } else { + return (String) value; } - - /** - * convenience method to get this value as a String. - * - * @return get this value as a String. - */ - @Override - public String getAsString() { - if (isNumber()) { - return getAsNumber().toString(); - } else if (isBoolean()) { - return getAsBooleanWrapper().toString(); - } else { - return (String) value; - } + } + + /** + * convenience method to get this value as a primitive double. + * + * @return get this value as a primitive double. + * @throws NumberFormatException if the value contained is not a valid double. + */ + @Override + public double getAsDouble() { + return isNumber() ? getAsNumber().doubleValue() : Double.parseDouble(getAsString()); + } + + /** + * convenience method to get this value as a float. + * + * @return get this value as a float. + * @throws NumberFormatException if the value contained is not a valid float. + */ + @Override + public float getAsFloat() { + return isNumber() ? getAsNumber().floatValue() : Float.parseFloat(getAsString()); + } + + /** + * convenience method to get this value as a primitive long. + * + * @return get this value as a primitive long. + * @throws NumberFormatException if the value contained is not a valid long. + */ + @Override + public long getAsLong() { + return isNumber() ? getAsNumber().longValue() : Long.parseLong(getAsString()); + } + + /** + * convenience method to get this value as a primitive integer. + * + * @return get this value as a primitive integer. + * @throws NumberFormatException if the value contained is not a valid integer. + */ + @Override + public int getAsInt() { + return isNumber() ? getAsNumber().intValue() : Integer.parseInt(getAsString()); + } + + @Override + public char getAsCharacter() { + return getAsString().charAt(0); + } + + @Override + public int hashCode() { + if (value == null) { + return 31; } - - /** - * convenience method to get this value as a primitive double. - * - * @return get this value as a primitive double. - * @throws NumberFormatException if the value contained is not a valid double. - */ - @Override - public double getAsDouble() { - return isNumber() ? getAsNumber().doubleValue() : Double.parseDouble(getAsString()); + // Using recommended hashing algorithm from Effective Java for longs and doubles + if (isIntegral(this)) { + long value = getAsNumber().longValue(); + return (int) (value ^ (value >>> 32)); } - - /** - * convenience method to get this value as a float. - * - * @return get this value as a float. - * @throws NumberFormatException if the value contained is not a valid float. - */ - @Override - public float getAsFloat() { - return isNumber() ? getAsNumber().floatValue() : Float.parseFloat(getAsString()); + if (value instanceof Number) { + long value = Double.doubleToLongBits(getAsNumber().doubleValue()); + return (int) (value ^ (value >>> 32)); } + return value.hashCode(); + } - /** - * convenience method to get this value as a primitive long. - * - * @return get this value as a primitive long. - * @throws NumberFormatException if the value contained is not a valid long. - */ - @Override - public long getAsLong() { - return isNumber() ? getAsNumber().longValue() : Long.parseLong(getAsString()); + @Override + public boolean equals(java.lang.Object obj) { + if (this == obj) { + return true; } - - /** - * convenience method to get this value as a primitive integer. - * - * @return get this value as a primitive integer. - * @throws NumberFormatException if the value contained is not a valid integer. - */ - @Override - public int getAsInt() { - return isNumber() ? getAsNumber().intValue() : Integer.parseInt(getAsString()); + if (obj == null || getClass() != obj.getClass()) { + return false; } - - @Override - public char getAsCharacter() { - return getAsString().charAt(0); + Primitive other = (Primitive) obj; + if (value == null) { + return other.value == null; } - - @Override - public int hashCode() { - if (value == null) { - return 31; - } - // Using recommended hashing algorithm from Effective Java for longs and doubles - if (isIntegral(this)) { - long value = getAsNumber().longValue(); - return (int) (value ^ (value >>> 32)); - } - if (value instanceof Number) { - long value = Double.doubleToLongBits(getAsNumber().doubleValue()); - return (int) (value ^ (value >>> 32)); - } - return value.hashCode(); + if (isIntegral(this) && isIntegral(other)) { + return getAsNumber().longValue() == other.getAsNumber().longValue(); } - - @Override - public boolean equals(java.lang.Object obj) { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - Primitive other = (Primitive) obj; - if (value == null) { - return other.value == null; - } - if (isIntegral(this) && isIntegral(other)) { - return getAsNumber().longValue() == other.getAsNumber().longValue(); - } - if (value instanceof Number && other.value instanceof Number) { - double a = getAsNumber().doubleValue(); - // Java standard types other than double return true for two NaN. So, need - // special handling for double. - double b = other.getAsNumber().doubleValue(); - return a == b || (Double.isNaN(a) && Double.isNaN(b)); - } - return value.equals(other.value); + if (value instanceof Number && other.value instanceof Number) { + double a = getAsNumber().doubleValue(); + // Java standard types other than double return true for two NaN. So, need + // special handling for double. + double b = other.getAsNumber().doubleValue(); + return a == b || (Double.isNaN(a) && Double.isNaN(b)); } + return value.equals(other.value); + } - @Override - public String toString() { - return getAsString(); - } + @Override + public String toString() { + return getAsString(); + } - public String getAsSingleQuotedString() { - return '\'' + getAsString() + '\''; - } + public String getAsSingleQuotedString() { + return '\'' + getAsString() + '\''; + } - public String getAsDoubleQuotedString() { - return '\"' + getAsString() + '\"'; - } + public String getAsDoubleQuotedString() { + return '\"' + getAsString() + '\"'; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Resource.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Resource.java index bf903dbb..94415c9a 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Resource.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Resource.java @@ -37,196 +37,196 @@ public class Resource extends Value { - public static final String RESOURCE_PREFIX_ANIMATION = "@anim/"; - public static final String RESOURCE_PREFIX_BOOLEAN = "@bool/"; - public static final String RESOURCE_PREFIX_COLOR = "@color/"; - public static final String RESOURCE_PREFIX_DIMENSION = "@dimen/"; - public static final String RESOURCE_PREFIX_DRAWABLE = "@drawable/"; - public static final String RESOURCE_PREFIX_STRING = "@string/"; - - public static final String ANIM = "anim"; - public static final String BOOLEAN = "bool"; - public static final String COLOR = "color"; - public static final String DIMEN = "dimen"; - public static final String DRAWABLE = "drawable"; - public static final String STRING = "string"; - - public static final Resource NOT_FOUND = new Resource(0); - - public final int resId; - - private Resource(int resId) { - this.resId = resId; - } - - public static boolean isAnimation(String string) { - return string.startsWith(RESOURCE_PREFIX_ANIMATION); - } - - public static boolean isBoolean(String string) { - return string.startsWith(RESOURCE_PREFIX_BOOLEAN); - } - - public static boolean isColor(String string) { - return string.startsWith(RESOURCE_PREFIX_COLOR); - } - - public static boolean isDimension(String string) { - return string.startsWith(RESOURCE_PREFIX_DIMENSION); - } - - public static boolean isDrawable(String string) { - return string.startsWith(RESOURCE_PREFIX_DRAWABLE); - } - - public static boolean isString(String string) { - return string.startsWith(RESOURCE_PREFIX_STRING); - } - - public static boolean isResource(String string) { - return isAnimation(string) || isBoolean(string) || isColor(string) || isDimension(string) || isDrawable(string) || isString(string); - } - - @Nullable - public static Boolean getBoolean(int resId, Context context) { - try { - return context.getResources().getBoolean(resId); - } catch (Resources.NotFoundException e) { - return null; - } - } - - @Nullable - public static Integer getColor(int resId, Context context) { - try { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - return context.getResources().getColor(resId, context.getTheme()); - } else { - //noinspection deprecation - return context.getResources().getColor(resId); - } - } catch (Resources.NotFoundException e) { - return null; - } - } - - @Nullable - public static ColorStateList getColorStateList(int resId, Context context) { - try { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - return context.getColorStateList(resId); - } else { - //noinspection deprecation - return context.getResources().getColorStateList(resId); - } - - } catch (Resources.NotFoundException nfe) { - return null; - } - } - - @Nullable - public static Drawable getDrawable(int resId, Context context) { - try { - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { - return context.getResources().getDrawable(resId, context.getTheme()); - } else { - //noinspection deprecation - return context.getResources().getDrawable(resId); - } - } catch (Resources.NotFoundException e) { - return null; - } - } - - @Nullable - public static Float getDimension(int resId, Context context) { - try { - return context.getResources().getDimension(resId); - } catch (Resources.NotFoundException e) { - return null; - } - } - - @Nullable - public static String getString(int resId, Context context) { - try { - return context.getString(resId); - } catch (Resources.NotFoundException e) { - return null; - } - } - - @Nullable - public static Resource valueOf(String value, @Nullable @ResourceType String type, Context context) { - if (null == value) { - return null; - } - Resource resource = ResourceCache.cache.get(value); - if (null == resource) { - int resId = context.getResources().getIdentifier(value, type, context.getPackageName()); - resource = resId == 0 ? NOT_FOUND : new Resource(resId); - ResourceCache.cache.put(value, resource); - } - return NOT_FOUND == resource ? null : resource; - } - - @NonNull - public static Resource valueOf(int resId) { - return new Resource(resId); - } - - @Nullable - public Boolean getBoolean(Context context) { - return getBoolean(resId, context); - } - - @Nullable - public Integer getColor(Context context) { - return getColor(resId, context); - } - - @Nullable - public ColorStateList getColorStateList(Context context) { - return getColorStateList(resId, context); - } - - @Nullable - public Drawable getDrawable(Context context) { - return getDrawable(resId, context); - } - - @Nullable - public Float getDimension(Context context) { - return getDimension(resId, context); - } - - @Nullable - public Integer getInteger(Context context) { - return getInteger(resId, context); - } - - @Nullable - public String getString(Context context) { - return getString(resId, context); - } - - @Nullable - public Integer getInteger(int resId, Context context) { - return context.getResources().getInteger(resId); - } - - @Override - public Value copy() { - return this; - } - - @StringDef({ANIM, BOOLEAN, COLOR, DRAWABLE, DIMEN, STRING}) - @Retention(RetentionPolicy.SOURCE) - public @interface ResourceType { - } - - private static class ResourceCache { - static final LruCache cache = new LruCache<>(64); - } + public static final String RESOURCE_PREFIX_ANIMATION = "@anim/"; + public static final String RESOURCE_PREFIX_BOOLEAN = "@bool/"; + public static final String RESOURCE_PREFIX_COLOR = "@color/"; + public static final String RESOURCE_PREFIX_DIMENSION = "@dimen/"; + public static final String RESOURCE_PREFIX_DRAWABLE = "@drawable/"; + public static final String RESOURCE_PREFIX_STRING = "@string/"; + + public static final String ANIM = "anim"; + public static final String BOOLEAN = "bool"; + public static final String COLOR = "color"; + public static final String DIMEN = "dimen"; + public static final String DRAWABLE = "drawable"; + public static final String STRING = "string"; + + public static final Resource NOT_FOUND = new Resource(0); + + public final int resId; + + private Resource(int resId) { + this.resId = resId; + } + + public static boolean isAnimation(String string) { + return string.startsWith(RESOURCE_PREFIX_ANIMATION); + } + + public static boolean isBoolean(String string) { + return string.startsWith(RESOURCE_PREFIX_BOOLEAN); + } + + public static boolean isColor(String string) { + return string.startsWith(RESOURCE_PREFIX_COLOR); + } + + public static boolean isDimension(String string) { + return string.startsWith(RESOURCE_PREFIX_DIMENSION); + } + + public static boolean isDrawable(String string) { + return string.startsWith(RESOURCE_PREFIX_DRAWABLE); + } + + public static boolean isString(String string) { + return string.startsWith(RESOURCE_PREFIX_STRING); + } + + public static boolean isResource(String string) { + return isAnimation(string) || isBoolean(string) || isColor(string) || isDimension(string) || isDrawable(string) || isString(string); + } + + @Nullable + public static Boolean getBoolean(int resId, Context context) { + try { + return context.getResources().getBoolean(resId); + } catch (Resources.NotFoundException e) { + return null; + } + } + + @Nullable + public static Integer getColor(int resId, Context context) { + try { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + return context.getResources().getColor(resId, context.getTheme()); + } else { + //noinspection deprecation + return context.getResources().getColor(resId); + } + } catch (Resources.NotFoundException e) { + return null; + } + } + + @Nullable + public static ColorStateList getColorStateList(int resId, Context context) { + try { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + return context.getColorStateList(resId); + } else { + //noinspection deprecation + return context.getResources().getColorStateList(resId); + } + + } catch (Resources.NotFoundException nfe) { + return null; + } + } + + @Nullable + public static Drawable getDrawable(int resId, Context context) { + try { + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { + return context.getResources().getDrawable(resId, context.getTheme()); + } else { + //noinspection deprecation + return context.getResources().getDrawable(resId); + } + } catch (Resources.NotFoundException e) { + return null; + } + } + + @Nullable + public static Float getDimension(int resId, Context context) { + try { + return context.getResources().getDimension(resId); + } catch (Resources.NotFoundException e) { + return null; + } + } + + @Nullable + public static String getString(int resId, Context context) { + try { + return context.getString(resId); + } catch (Resources.NotFoundException e) { + return null; + } + } + + @Nullable + public static Resource valueOf(String value, @Nullable @ResourceType String type, Context context) { + if (null == value) { + return null; + } + Resource resource = ResourceCache.cache.get(value); + if (null == resource) { + int resId = context.getResources().getIdentifier(value, type, context.getPackageName()); + resource = resId == 0 ? NOT_FOUND : new Resource(resId); + ResourceCache.cache.put(value, resource); + } + return NOT_FOUND == resource ? null : resource; + } + + @NonNull + public static Resource valueOf(int resId) { + return new Resource(resId); + } + + @Nullable + public Boolean getBoolean(Context context) { + return getBoolean(resId, context); + } + + @Nullable + public Integer getColor(Context context) { + return getColor(resId, context); + } + + @Nullable + public ColorStateList getColorStateList(Context context) { + return getColorStateList(resId, context); + } + + @Nullable + public Drawable getDrawable(Context context) { + return getDrawable(resId, context); + } + + @Nullable + public Float getDimension(Context context) { + return getDimension(resId, context); + } + + @Nullable + public Integer getInteger(Context context) { + return getInteger(resId, context); + } + + @Nullable + public String getString(Context context) { + return getString(resId, context); + } + + @Nullable + public Integer getInteger(int resId, Context context) { + return context.getResources().getInteger(resId); + } + + @Override + public Value copy() { + return this; + } + + @StringDef({ANIM, BOOLEAN, COLOR, DRAWABLE, DIMEN, STRING}) + @Retention(RetentionPolicy.SOURCE) + public @interface ResourceType { + } + + private static class ResourceCache { + static final LruCache cache = new LruCache<>(64); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/StyleResource.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/StyleResource.java index b9447b43..e38de030 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/StyleResource.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/StyleResource.java @@ -35,88 +35,88 @@ public class StyleResource extends Value { - public static final StyleResource NULL = new StyleResource(-1, -1); - private static final Map styleMap = new HashMap<>(); - private static final Map attributeMap = new HashMap<>(); - private static final Map sHashMap = new HashMap<>(); - private static final String ATTR_START_LITERAL = "?"; - - public final int styleId; - public final int attributeId; - - private StyleResource(String value, Context context) throws IllegalArgumentException, NoSuchFieldException, IllegalAccessException, ClassNotFoundException { - String[] tokens = value.substring(1, value.length()).split(":"); - String style = tokens[0]; - String attr = tokens[1]; - Class clazz; - - Integer styleId = styleMap.get(style); - if (styleId == null) { - String className = context.getPackageName() + ".R$style"; - clazz = sHashMap.get(className); - if (null == clazz) { - clazz = Class.forName(className); - sHashMap.put(className, clazz); - } - styleId = clazz.getField(style).getInt(null); - styleMap.put(style, styleId); - } - this.styleId = styleId; - Integer attrId = attributeMap.get(attr); - if (attrId == null) { - String className = context.getPackageName() + ".R$attr"; - clazz = sHashMap.get(className); - if (null == clazz) { - clazz = Class.forName(className); - sHashMap.put(className, clazz); - } - attrId = clazz.getField(attr).getInt(null); - attributeMap.put(attr, attrId); - } - this.attributeId = attrId; + public static final StyleResource NULL = new StyleResource(-1, -1); + private static final Map styleMap = new HashMap<>(); + private static final Map attributeMap = new HashMap<>(); + private static final Map sHashMap = new HashMap<>(); + private static final String ATTR_START_LITERAL = "?"; + + public final int styleId; + public final int attributeId; + + private StyleResource(String value, Context context) throws IllegalArgumentException, NoSuchFieldException, IllegalAccessException, ClassNotFoundException { + String[] tokens = value.substring(1, value.length()).split(":"); + String style = tokens[0]; + String attr = tokens[1]; + Class clazz; + + Integer styleId = styleMap.get(style); + if (styleId == null) { + String className = context.getPackageName() + ".R$style"; + clazz = sHashMap.get(className); + if (null == clazz) { + clazz = Class.forName(className); + sHashMap.put(className, clazz); + } + styleId = clazz.getField(style).getInt(null); + styleMap.put(style, styleId); } - - private StyleResource(int styleId, int attributeId) { - this.styleId = styleId; - this.attributeId = attributeId; + this.styleId = styleId; + Integer attrId = attributeMap.get(attr); + if (attrId == null) { + String className = context.getPackageName() + ".R$attr"; + clazz = sHashMap.get(className); + if (null == clazz) { + clazz = Class.forName(className); + sHashMap.put(className, clazz); + } + attrId = clazz.getField(attr).getInt(null); + attributeMap.put(attr, attrId); } - - public static boolean isStyleResource(String value) { - return value.startsWith(ATTR_START_LITERAL); - } - - @Nullable - public static StyleResource valueOf(String value, Context context) { - StyleResource style = StyleCache.cache.get(value); - if (null == style) { - try { - style = new StyleResource(value, context); - } catch (Exception e) { - if (ProteusConstants.isLoggingEnabled()) { - e.printStackTrace(); - } - style = NULL; - } - StyleCache.cache.put(value, style); + this.attributeId = attrId; + } + + private StyleResource(int styleId, int attributeId) { + this.styleId = styleId; + this.attributeId = attributeId; + } + + public static boolean isStyleResource(String value) { + return value.startsWith(ATTR_START_LITERAL); + } + + @Nullable + public static StyleResource valueOf(String value, Context context) { + StyleResource style = StyleCache.cache.get(value); + if (null == style) { + try { + style = new StyleResource(value, context); + } catch (Exception e) { + if (ProteusConstants.isLoggingEnabled()) { + e.printStackTrace(); } - return NULL == style ? null : style; - } - - @NonNull - public static StyleResource valueOf(int styleId, int attributeId) { - return new StyleResource(styleId, attributeId); - } - - public TypedArray apply(Context context) { - return context.obtainStyledAttributes(styleId, new int[]{attributeId}); - } - - @Override - public Value copy() { - return this; - } - - private static class StyleCache { - static final LruCache cache = new LruCache<>(64); + style = NULL; + } + StyleCache.cache.put(value, style); } + return NULL == style ? null : style; + } + + @NonNull + public static StyleResource valueOf(int styleId, int attributeId) { + return new StyleResource(styleId, attributeId); + } + + public TypedArray apply(Context context) { + return context.obtainStyledAttributes(styleId, new int[]{attributeId}); + } + + @Override + public Value copy() { + return this; + } + + private static class StyleCache { + static final LruCache cache = new LruCache<>(64); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Value.java b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Value.java index 4e3a6bf0..6844b913 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/value/Value.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/value/Value.java @@ -23,325 +23,325 @@ */ public abstract class Value { - /** - * Returns a deep copy of this value. Immutable elements - * like primitives and nulls are not copied. - */ - public abstract Value copy(); - - /** - * provides check for verifying if this value is an array or not. - * - * @return true if this value is of type {@link Array}, false otherwise. - */ - public boolean isArray() { - return this instanceof Array; + /** + * Returns a deep copy of this value. Immutable elements + * like primitives and nulls are not copied. + */ + public abstract Value copy(); + + /** + * provides check for verifying if this value is an array or not. + * + * @return true if this value is of type {@link Array}, false otherwise. + */ + public boolean isArray() { + return this instanceof Array; + } + + /** + * provides check for verifying if this value is a object or not. + * + * @return true if this value is of type {@link ObjectValue}, false otherwise. + */ + public boolean isObject() { + return this instanceof ObjectValue; + } + + /** + * provides check for verifying if this value is a primitive or not. + * + * @return true if this value is of type {@link Primitive}, false otherwise. + */ + public boolean isPrimitive() { + return this instanceof Primitive; + } + + /** + * provides check for verifying if this value represents a null value or not. + * + * @return true if this value is of type {@link Null}, false otherwise. + * @since 1.2 + */ + public boolean isNull() { + return this instanceof Null; + } + + /** + * @return + */ + public boolean isLayout() { + return this instanceof Layout; + } + + /** + * @return + */ + public boolean isDimension() { + return this instanceof Dimension; + } + + /** + * @return + */ + public boolean isStyleResource() { + return this instanceof StyleResource; + } + + /** + * @return + */ + public boolean isColor() { + return this instanceof Color; + } + + /** + * @return + */ + public boolean isAttributeResource() { + return this instanceof AttributeResource; + } + + /** + * @return + */ + public boolean isResource() { + return this instanceof Resource; + } + + /** + * @return + */ + public boolean isBinding() { + return this instanceof Binding; + } + + /** + * @return + */ + public boolean isDrawable() { + return this instanceof DrawableValue; + } + + /** + * convenience method to get this value as a {@link ObjectValue}. If the value is of some + * other type, a {@link IllegalStateException} will result. Hence it is best to use this method + * after ensuring that this value is of the desired type by calling {@link #isObject()} + * first. + * + * @return get this value as a {@link ObjectValue}. + * @throws IllegalStateException if the value is of another type. + */ + public ObjectValue getAsObject() { + if (isObject()) { + return (ObjectValue) this; } - - /** - * provides check for verifying if this value is a object or not. - * - * @return true if this value is of type {@link ObjectValue}, false otherwise. - */ - public boolean isObject() { - return this instanceof ObjectValue; + throw new IllegalStateException("Not an ObjectValue: " + this); + } + + /** + * convenience method to get this value as a {@link Array}. If the value is of some + * other type, a {@link IllegalStateException} will result. Hence it is best to use this method + * after ensuring that this value is of the desired type by calling {@link #isArray()} + * first. + * + * @return get this value as a {@link Array}. + * @throws IllegalStateException if the value is of another type. + */ + public Array getAsArray() { + if (isArray()) { + return (Array) this; } - - /** - * provides check for verifying if this value is a primitive or not. - * - * @return true if this value is of type {@link Primitive}, false otherwise. - */ - public boolean isPrimitive() { - return this instanceof Primitive; + throw new IllegalStateException("This is not a Array."); + } + + /** + * convenience method to get this value as a {@link Primitive}. If the value is of some + * other type, a {@link IllegalStateException} will result. Hence it is best to use this method + * after ensuring that this value is of the desired type by calling {@link #isPrimitive()} + * first. + * + * @return get this value as a {@link Primitive}. + * @throws IllegalStateException if the value is of another type. + */ + public Primitive getAsPrimitive() { + if (isPrimitive()) { + return (Primitive) this; } - - /** - * provides check for verifying if this value represents a null value or not. - * - * @return true if this value is of type {@link Null}, false otherwise. - * @since 1.2 - */ - public boolean isNull() { - return this instanceof Null; + throw new IllegalStateException("This is not a Primitive."); + } + + /** + * convenience method to get this value as a {@link Null}. If the value is of some + * other type, a {@link IllegalStateException} will result. Hence it is best to use this method + * after ensuring that this value is of the desired type by calling {@link #isNull()} + * first. + * + * @return get this value as a {@link Null}. + * @throws IllegalStateException if the value is of another type. + * @since 1.2 + */ + public Null getAsNull() { + if (isNull()) { + return (Null) this; } - - /** - * @return - */ - public boolean isLayout() { - return this instanceof Layout; + throw new IllegalStateException("This is not a Null."); + } + + /** + * @return + */ + public Layout getAsLayout() { + if (isLayout()) { + return (Layout) this; } - - /** - * @return - */ - public boolean isDimension() { - return this instanceof Dimension; + throw new IllegalStateException("Not a Layout: " + this); + } + + /** + * @return + */ + public Dimension getAsDimension() { + if (isDimension()) { + return (Dimension) this; } - - /** - * @return - */ - public boolean isStyleResource() { - return this instanceof StyleResource; + throw new IllegalStateException("Not a Dimension: " + this); + } + + /** + * @return + */ + public StyleResource getAsStyleResource() { + if (isStyleResource()) { + return (StyleResource) this; } - - /** - * @return - */ - public boolean isColor() { - return this instanceof Color; + throw new IllegalStateException("Not a StyleResource: " + this); + } + + /** + * @return + */ + public AttributeResource getAsAttributeResource() { + if (isAttributeResource()) { + return (AttributeResource) this; } - - /** - * @return - */ - public boolean isAttributeResource() { - return this instanceof AttributeResource; - } - - /** - * @return - */ - public boolean isResource() { - return this instanceof Resource; + throw new IllegalStateException("Not a Resource: " + this); + } + + /** + * @return + */ + public Color getAsColor() { + if (isColor()) { + return (Color) this; } - - /** - * @return - */ - public boolean isBinding() { - return this instanceof Binding; + throw new IllegalStateException("Not a ColorValue: " + this); + } + + /** + * @return + */ + public Resource getAsResource() { + if (isResource()) { + return (Resource) this; } - - /** - * @return - */ - public boolean isDrawable() { - return this instanceof DrawableValue; + throw new IllegalStateException("Not a Resource: " + this); + } + + /** + * @return + */ + public Binding getAsBinding() { + if (isBinding()) { + return (Binding) this; } - - /** - * convenience method to get this value as a {@link ObjectValue}. If the value is of some - * other type, a {@link IllegalStateException} will result. Hence it is best to use this method - * after ensuring that this value is of the desired type by calling {@link #isObject()} - * first. - * - * @return get this value as a {@link ObjectValue}. - * @throws IllegalStateException if the value is of another type. - */ - public ObjectValue getAsObject() { - if (isObject()) { - return (ObjectValue) this; - } - throw new IllegalStateException("Not an ObjectValue: " + this); - } - - /** - * convenience method to get this value as a {@link Array}. If the value is of some - * other type, a {@link IllegalStateException} will result. Hence it is best to use this method - * after ensuring that this value is of the desired type by calling {@link #isArray()} - * first. - * - * @return get this value as a {@link Array}. - * @throws IllegalStateException if the value is of another type. - */ - public Array getAsArray() { - if (isArray()) { - return (Array) this; - } - throw new IllegalStateException("This is not a Array."); - } - - /** - * convenience method to get this value as a {@link Primitive}. If the value is of some - * other type, a {@link IllegalStateException} will result. Hence it is best to use this method - * after ensuring that this value is of the desired type by calling {@link #isPrimitive()} - * first. - * - * @return get this value as a {@link Primitive}. - * @throws IllegalStateException if the value is of another type. - */ - public Primitive getAsPrimitive() { - if (isPrimitive()) { - return (Primitive) this; - } - throw new IllegalStateException("This is not a Primitive."); - } - - /** - * convenience method to get this value as a {@link Null}. If the value is of some - * other type, a {@link IllegalStateException} will result. Hence it is best to use this method - * after ensuring that this value is of the desired type by calling {@link #isNull()} - * first. - * - * @return get this value as a {@link Null}. - * @throws IllegalStateException if the value is of another type. - * @since 1.2 - */ - public Null getAsNull() { - if (isNull()) { - return (Null) this; - } - throw new IllegalStateException("This is not a Null."); - } - - /** - * @return - */ - public Layout getAsLayout() { - if (isLayout()) { - return (Layout) this; - } - throw new IllegalStateException("Not a Layout: " + this); - } - - /** - * @return - */ - public Dimension getAsDimension() { - if (isDimension()) { - return (Dimension) this; - } - throw new IllegalStateException("Not a Dimension: " + this); - } - - /** - * @return - */ - public StyleResource getAsStyleResource() { - if (isStyleResource()) { - return (StyleResource) this; - } - throw new IllegalStateException("Not a StyleResource: " + this); - } - - /** - * @return - */ - public AttributeResource getAsAttributeResource() { - if (isAttributeResource()) { - return (AttributeResource) this; - } - throw new IllegalStateException("Not a Resource: " + this); - } - - /** - * @return - */ - public Color getAsColor() { - if (isColor()) { - return (Color) this; - } - throw new IllegalStateException("Not a ColorValue: " + this); - } - - /** - * @return - */ - public Resource getAsResource() { - if (isResource()) { - return (Resource) this; - } - throw new IllegalStateException("Not a Resource: " + this); - } - - /** - * @return - */ - public Binding getAsBinding() { - if (isBinding()) { - return (Binding) this; - } - throw new IllegalStateException("Not a Binding: " + this); - } - - /** - * @return - */ - public DrawableValue getAsDrawable() { - if (isDrawable()) { - return (DrawableValue) this; - } - throw new IllegalStateException("Not a Drawable: " + this); - } - - /** - * convenience method to get this value as a boolean value. - * - * @return get this value as a primitive boolean value. - * @throws ClassCastException if the value is of not a {@link Primitive} and is not a valid - * boolean value. - */ - public boolean getAsBoolean() { - throw new UnsupportedOperationException(getClass().getSimpleName()); - } - - /** - * convenience method to get this value as a string value. - * - * @return get this value as a string value. - * @throws ClassCastException if the value is of not a {@link Primitive} and is not a valid - * string value. - */ - public String getAsString() { - throw new UnsupportedOperationException(getClass().getSimpleName()); - } - - /** - * convenience method to get this value as a primitive double value. - * - * @return get this value as a primitive double value. - * @throws ClassCastException if the value is of not a {@link Primitive} and is not a valid - * double value. - */ - public double getAsDouble() { - throw new UnsupportedOperationException(getClass().getSimpleName()); - } - - /** - * convenience method to get this value as a primitive float value. - * - * @return get this value as a primitive float value. - * @throws ClassCastException if the value is of not a {@link Primitive} and is not a valid - * float value. - */ - public float getAsFloat() { - throw new UnsupportedOperationException(getClass().getSimpleName()); - } - - /** - * convenience method to get this value as a primitive long value. - * - * @return get this value as a primitive long value. - * @throws ClassCastException if the value is of not a {@link Primitive} and is not a valid - * long value. - */ - public long getAsLong() { - throw new UnsupportedOperationException(getClass().getSimpleName()); - } - - /** - * convenience method to get this value as a primitive integer value. - * - * @return get this value as a primitive integer value. - * @throws ClassCastException if the value is of not a {@link Primitive} and is not a valid - * integer value. - */ - public int getAsInt() { - throw new UnsupportedOperationException(getClass().getSimpleName()); - } - - /** - * convenience method to get this value as a primitive character value. - * - * @return get this value as a primitive char value. - * @throws ClassCastException if the value is of not a {@link Primitive} and is not a valid - * char value. - */ - public char getAsCharacter() { - throw new UnsupportedOperationException(getClass().getSimpleName()); + throw new IllegalStateException("Not a Binding: " + this); + } + + /** + * @return + */ + public DrawableValue getAsDrawable() { + if (isDrawable()) { + return (DrawableValue) this; } + throw new IllegalStateException("Not a Drawable: " + this); + } + + /** + * convenience method to get this value as a boolean value. + * + * @return get this value as a primitive boolean value. + * @throws ClassCastException if the value is of not a {@link Primitive} and is not a valid + * boolean value. + */ + public boolean getAsBoolean() { + throw new UnsupportedOperationException(getClass().getSimpleName()); + } + + /** + * convenience method to get this value as a string value. + * + * @return get this value as a string value. + * @throws ClassCastException if the value is of not a {@link Primitive} and is not a valid + * string value. + */ + public String getAsString() { + throw new UnsupportedOperationException(getClass().getSimpleName()); + } + + /** + * convenience method to get this value as a primitive double value. + * + * @return get this value as a primitive double value. + * @throws ClassCastException if the value is of not a {@link Primitive} and is not a valid + * double value. + */ + public double getAsDouble() { + throw new UnsupportedOperationException(getClass().getSimpleName()); + } + + /** + * convenience method to get this value as a primitive float value. + * + * @return get this value as a primitive float value. + * @throws ClassCastException if the value is of not a {@link Primitive} and is not a valid + * float value. + */ + public float getAsFloat() { + throw new UnsupportedOperationException(getClass().getSimpleName()); + } + + /** + * convenience method to get this value as a primitive long value. + * + * @return get this value as a primitive long value. + * @throws ClassCastException if the value is of not a {@link Primitive} and is not a valid + * long value. + */ + public long getAsLong() { + throw new UnsupportedOperationException(getClass().getSimpleName()); + } + + /** + * convenience method to get this value as a primitive integer value. + * + * @return get this value as a primitive integer value. + * @throws ClassCastException if the value is of not a {@link Primitive} and is not a valid + * integer value. + */ + public int getAsInt() { + throw new UnsupportedOperationException(getClass().getSimpleName()); + } + + /** + * convenience method to get this value as a primitive character value. + * + * @return get this value as a primitive char value. + * @throws ClassCastException if the value is of not a {@link Primitive} and is not a valid + * char value. + */ + public char getAsCharacter() { + throw new UnsupportedOperationException(getClass().getSimpleName()); + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusAndroidView.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusAndroidView.java index 7d651acd..1a250b94 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusAndroidView.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusAndroidView.java @@ -32,38 +32,38 @@ */ public class ProteusAndroidView extends android.view.View implements ProteusView { - Manager viewManager; + Manager viewManager; - public ProteusAndroidView(Context context) { - super(context); - } + public ProteusAndroidView(Context context) { + super(context); + } - public ProteusAndroidView(Context context, AttributeSet attrs) { - super(context, attrs); - } + public ProteusAndroidView(Context context, AttributeSet attrs) { + super(context, attrs); + } - public ProteusAndroidView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } + public ProteusAndroidView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public ProteusAndroidView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public ProteusAndroidView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } - @Override - public Manager getViewManager() { - return viewManager; - } + @Override + public Manager getViewManager() { + return viewManager; + } - @Override - public void setViewManager(@NonNull Manager manager) { - this.viewManager = manager; - } + @Override + public void setViewManager(@NonNull Manager manager) { + this.viewManager = manager; + } - @NonNull - @Override - public View getAsView() { - return this; - } + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusAspectRatioFrameLayout.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusAspectRatioFrameLayout.java index 71d0610e..0fd9a19f 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusAspectRatioFrameLayout.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusAspectRatioFrameLayout.java @@ -32,38 +32,38 @@ */ public class ProteusAspectRatioFrameLayout extends com.flipkart.android.proteus.view.custom.AspectRatioFrameLayout implements ProteusView { - private Manager viewManager; + private Manager viewManager; - public ProteusAspectRatioFrameLayout(Context context) { - super(context); - } + public ProteusAspectRatioFrameLayout(Context context) { + super(context); + } - public ProteusAspectRatioFrameLayout(Context context, AttributeSet attrs) { - super(context, attrs); - } + public ProteusAspectRatioFrameLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } - public ProteusAspectRatioFrameLayout(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } + public ProteusAspectRatioFrameLayout(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public ProteusAspectRatioFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public ProteusAspectRatioFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } - @Override - public Manager getViewManager() { - return viewManager; - } + @Override + public Manager getViewManager() { + return viewManager; + } - @Override - public void setViewManager(@NonNull Manager manager) { - this.viewManager = manager; - } + @Override + public void setViewManager(@NonNull Manager manager) { + this.viewManager = manager; + } - @NonNull - @Override - public View getAsView() { - return this; - } + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusButton.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusButton.java index 26e50626..1fab19e1 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusButton.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusButton.java @@ -32,38 +32,38 @@ */ public class ProteusButton extends android.widget.Button implements ProteusView { - Manager viewManager; + Manager viewManager; - public ProteusButton(Context context) { - super(context); - } + public ProteusButton(Context context) { + super(context); + } - public ProteusButton(Context context, AttributeSet attrs) { - super(context, attrs); - } + public ProteusButton(Context context, AttributeSet attrs) { + super(context, attrs); + } - public ProteusButton(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } + public ProteusButton(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public ProteusButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public ProteusButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } - @Override - public Manager getViewManager() { - return viewManager; - } + @Override + public Manager getViewManager() { + return viewManager; + } - @Override - public void setViewManager(@NonNull Manager manager) { - this.viewManager = manager; - } + @Override + public void setViewManager(@NonNull Manager manager) { + this.viewManager = manager; + } - @NonNull - @Override - public View getAsView() { - return this; - } + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusCheckBox.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusCheckBox.java index ac680a2f..8a5a4703 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusCheckBox.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusCheckBox.java @@ -32,38 +32,38 @@ */ public class ProteusCheckBox extends android.widget.CheckBox implements ProteusView { - private Manager viewManager; + private Manager viewManager; - public ProteusCheckBox(Context context) { - super(context); - } + public ProteusCheckBox(Context context) { + super(context); + } - public ProteusCheckBox(Context context, AttributeSet attrs) { - super(context, attrs); - } + public ProteusCheckBox(Context context, AttributeSet attrs) { + super(context, attrs); + } - public ProteusCheckBox(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } + public ProteusCheckBox(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public ProteusCheckBox(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public ProteusCheckBox(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } - @Override - public Manager getViewManager() { - return viewManager; - } + @Override + public Manager getViewManager() { + return viewManager; + } - @Override - public void setViewManager(@NonNull Manager manager) { - this.viewManager = manager; - } + @Override + public void setViewManager(@NonNull Manager manager) { + this.viewManager = manager; + } - @NonNull - @Override - public View getAsView() { - return this; - } + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusEditText.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusEditText.java index 6e2c904e..24a6538f 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusEditText.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusEditText.java @@ -32,38 +32,38 @@ */ public class ProteusEditText extends android.widget.EditText implements ProteusView { - private Manager viewManager; + private Manager viewManager; - public ProteusEditText(Context context) { - super(context); - } + public ProteusEditText(Context context) { + super(context); + } - public ProteusEditText(Context context, AttributeSet attrs) { - super(context, attrs); - } + public ProteusEditText(Context context, AttributeSet attrs) { + super(context, attrs); + } - public ProteusEditText(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } + public ProteusEditText(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public ProteusEditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public ProteusEditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } - @Override - public Manager getViewManager() { - return viewManager; - } + @Override + public Manager getViewManager() { + return viewManager; + } - @Override - public void setViewManager(@NonNull Manager manager) { - this.viewManager = manager; - } + @Override + public void setViewManager(@NonNull Manager manager) { + this.viewManager = manager; + } - @NonNull - @Override - public View getAsView() { - return this; - } + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusFixedRatingBar.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusFixedRatingBar.java index 6a08cc35..22ebf00c 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusFixedRatingBar.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusFixedRatingBar.java @@ -30,33 +30,33 @@ */ public class ProteusFixedRatingBar extends com.flipkart.android.proteus.view.custom.FixedRatingBar implements ProteusView { - private Manager viewManager; - - public ProteusFixedRatingBar(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - public ProteusFixedRatingBar(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public ProteusFixedRatingBar(Context context) { - super(context); - } - - @Override - public Manager getViewManager() { - return viewManager; - } - - @Override - public void setViewManager(@NonNull Manager manager) { - this.viewManager = manager; - } - - @NonNull - @Override - public View getAsView() { - return this; - } + private Manager viewManager; + + public ProteusFixedRatingBar(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public ProteusFixedRatingBar(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public ProteusFixedRatingBar(Context context) { + super(context); + } + + @Override + public Manager getViewManager() { + return viewManager; + } + + @Override + public void setViewManager(@NonNull Manager manager) { + this.viewManager = manager; + } + + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusHorizontalProgressBar.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusHorizontalProgressBar.java index e8483d9c..77d97edd 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusHorizontalProgressBar.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusHorizontalProgressBar.java @@ -29,25 +29,25 @@ */ public class ProteusHorizontalProgressBar extends com.flipkart.android.proteus.view.custom.HorizontalProgressBar implements ProteusView { - private Manager viewManager; - - public ProteusHorizontalProgressBar(Context context) { - super(context); - } - - @Override - public Manager getViewManager() { - return viewManager; - } - - @Override - public void setViewManager(@NonNull Manager manager) { - this.viewManager = manager; - } - - @NonNull - @Override - public View getAsView() { - return this; - } + private Manager viewManager; + + public ProteusHorizontalProgressBar(Context context) { + super(context); + } + + @Override + public Manager getViewManager() { + return viewManager; + } + + @Override + public void setViewManager(@NonNull Manager manager) { + this.viewManager = manager; + } + + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusHorizontalScrollView.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusHorizontalScrollView.java index 809e8de0..fafe3109 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusHorizontalScrollView.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusHorizontalScrollView.java @@ -32,38 +32,38 @@ */ public class ProteusHorizontalScrollView extends android.widget.HorizontalScrollView implements ProteusView { - private Manager viewManager; + private Manager viewManager; - public ProteusHorizontalScrollView(Context context) { - super(context); - } + public ProteusHorizontalScrollView(Context context) { + super(context); + } - public ProteusHorizontalScrollView(Context context, AttributeSet attrs) { - super(context, attrs); - } + public ProteusHorizontalScrollView(Context context, AttributeSet attrs) { + super(context, attrs); + } - public ProteusHorizontalScrollView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } + public ProteusHorizontalScrollView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public ProteusHorizontalScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public ProteusHorizontalScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } - @Override - public Manager getViewManager() { - return viewManager; - } + @Override + public Manager getViewManager() { + return viewManager; + } - @Override - public void setViewManager(@NonNull Manager manager) { - this.viewManager = manager; - } + @Override + public void setViewManager(@NonNull Manager manager) { + this.viewManager = manager; + } - @NonNull - @Override - public View getAsView() { - return this; - } + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusImageButton.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusImageButton.java index adb53345..1feedd39 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusImageButton.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusImageButton.java @@ -32,38 +32,38 @@ */ public class ProteusImageButton extends android.widget.ImageButton implements ProteusView { - private Manager viewManager; + private Manager viewManager; - public ProteusImageButton(Context context) { - super(context); - } + public ProteusImageButton(Context context) { + super(context); + } - public ProteusImageButton(Context context, AttributeSet attrs) { - super(context, attrs); - } + public ProteusImageButton(Context context, AttributeSet attrs) { + super(context, attrs); + } - public ProteusImageButton(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } + public ProteusImageButton(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public ProteusImageButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public ProteusImageButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } - @Override - public Manager getViewManager() { - return viewManager; - } + @Override + public Manager getViewManager() { + return viewManager; + } - @Override - public void setViewManager(@NonNull Manager manager) { - this.viewManager = manager; - } + @Override + public void setViewManager(@NonNull Manager manager) { + this.viewManager = manager; + } - @NonNull - @Override - public View getAsView() { - return this; - } + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusImageView.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusImageView.java index 5fbac206..dad6c158 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusImageView.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusImageView.java @@ -32,38 +32,38 @@ */ public class ProteusImageView extends android.widget.ImageView implements ProteusView { - private Manager viewManager; + private Manager viewManager; - public ProteusImageView(Context context) { - super(context); - } + public ProteusImageView(Context context) { + super(context); + } - public ProteusImageView(Context context, AttributeSet attrs) { - super(context, attrs); - } + public ProteusImageView(Context context, AttributeSet attrs) { + super(context, attrs); + } - public ProteusImageView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } + public ProteusImageView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public ProteusImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public ProteusImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } - @Override - public Manager getViewManager() { - return viewManager; - } + @Override + public Manager getViewManager() { + return viewManager; + } - @Override - public void setViewManager(@NonNull Manager manager) { - this.viewManager = manager; - } + @Override + public void setViewManager(@NonNull Manager manager) { + this.viewManager = manager; + } - @NonNull - @Override - public View getAsView() { - return this; - } + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusLinearLayout.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusLinearLayout.java index 60c3d192..2db44569 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusLinearLayout.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusLinearLayout.java @@ -32,38 +32,38 @@ */ public class ProteusLinearLayout extends android.widget.LinearLayout implements ProteusView { - private Manager viewManager; + private Manager viewManager; - public ProteusLinearLayout(Context context) { - super(context); - } + public ProteusLinearLayout(Context context) { + super(context); + } - public ProteusLinearLayout(Context context, AttributeSet attrs) { - super(context, attrs); - } + public ProteusLinearLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } - public ProteusLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } + public ProteusLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public ProteusLinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public ProteusLinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } - @Override - public Manager getViewManager() { - return viewManager; - } + @Override + public Manager getViewManager() { + return viewManager; + } - @Override - public void setViewManager(@NonNull Manager manager) { - this.viewManager = manager; - } + @Override + public void setViewManager(@NonNull Manager manager) { + this.viewManager = manager; + } - @NonNull - @Override - public View getAsView() { - return this; - } + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusProgressBar.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusProgressBar.java index 5879a99e..41a77516 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusProgressBar.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusProgressBar.java @@ -32,38 +32,38 @@ */ public class ProteusProgressBar extends android.widget.ProgressBar implements ProteusView { - private Manager viewManager; + private Manager viewManager; - public ProteusProgressBar(Context context) { - super(context); - } + public ProteusProgressBar(Context context) { + super(context); + } - public ProteusProgressBar(Context context, AttributeSet attrs) { - super(context, attrs); - } + public ProteusProgressBar(Context context, AttributeSet attrs) { + super(context, attrs); + } - public ProteusProgressBar(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } + public ProteusProgressBar(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public ProteusProgressBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public ProteusProgressBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } - @Override - public Manager getViewManager() { - return viewManager; - } + @Override + public Manager getViewManager() { + return viewManager; + } - @Override - public void setViewManager(@NonNull Manager manager) { - this.viewManager = manager; - } + @Override + public void setViewManager(@NonNull Manager manager) { + this.viewManager = manager; + } - @NonNull - @Override - public View getAsView() { - return this; - } + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusRelativeLayout.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusRelativeLayout.java index 6fbd5b36..e352c211 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusRelativeLayout.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusRelativeLayout.java @@ -32,38 +32,38 @@ */ public class ProteusRelativeLayout extends android.widget.RelativeLayout implements ProteusView { - private Manager viewManager; + private Manager viewManager; - public ProteusRelativeLayout(Context context) { - super(context); - } + public ProteusRelativeLayout(Context context) { + super(context); + } - public ProteusRelativeLayout(Context context, AttributeSet attrs) { - super(context, attrs); - } + public ProteusRelativeLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } - public ProteusRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } + public ProteusRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public ProteusRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public ProteusRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } - @Override - public Manager getViewManager() { - return viewManager; - } + @Override + public Manager getViewManager() { + return viewManager; + } - @Override - public void setViewManager(@NonNull Manager manager) { - this.viewManager = manager; - } + @Override + public void setViewManager(@NonNull Manager manager) { + this.viewManager = manager; + } - @NonNull - @Override - public View getAsView() { - return this; - } + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusScrollView.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusScrollView.java index e01062bc..9993a74d 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusScrollView.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusScrollView.java @@ -32,38 +32,38 @@ */ public class ProteusScrollView extends android.widget.ScrollView implements ProteusView { - private Manager viewManager; + private Manager viewManager; - public ProteusScrollView(Context context) { - super(context); - } + public ProteusScrollView(Context context) { + super(context); + } - public ProteusScrollView(Context context, AttributeSet attrs) { - super(context, attrs); - } + public ProteusScrollView(Context context, AttributeSet attrs) { + super(context, attrs); + } - public ProteusScrollView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } + public ProteusScrollView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public ProteusScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public ProteusScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } - @Override - public Manager getViewManager() { - return viewManager; - } + @Override + public Manager getViewManager() { + return viewManager; + } - @Override - public void setViewManager(@NonNull Manager manager) { - this.viewManager = manager; - } + @Override + public void setViewManager(@NonNull Manager manager) { + this.viewManager = manager; + } - @NonNull - @Override - public View getAsView() { - return this; - } + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusTextView.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusTextView.java index 63c86e54..b469fb29 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusTextView.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusTextView.java @@ -32,38 +32,38 @@ */ public class ProteusTextView extends android.widget.TextView implements ProteusView { - private Manager viewManager; + private Manager viewManager; - public ProteusTextView(Context context) { - super(context); - } + public ProteusTextView(Context context) { + super(context); + } - public ProteusTextView(Context context, AttributeSet attrs) { - super(context, attrs); - } + public ProteusTextView(Context context, AttributeSet attrs) { + super(context, attrs); + } - public ProteusTextView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } + public ProteusTextView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public ProteusTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public ProteusTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } - @Override - public Manager getViewManager() { - return viewManager; - } + @Override + public Manager getViewManager() { + return viewManager; + } - @Override - public void setViewManager(@NonNull Manager manager) { - this.viewManager = manager; - } + @Override + public void setViewManager(@NonNull Manager manager) { + this.viewManager = manager; + } - @NonNull - @Override - public View getAsView() { - return this; - } + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusWebView.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusWebView.java index d89f42fc..1d67ef52 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusWebView.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusWebView.java @@ -32,38 +32,38 @@ */ public class ProteusWebView extends android.webkit.WebView implements ProteusView { - private Manager viewManager; + private Manager viewManager; - public ProteusWebView(Context context) { - super(context); - } + public ProteusWebView(Context context) { + super(context); + } - public ProteusWebView(Context context, AttributeSet attrs) { - super(context, attrs); - } + public ProteusWebView(Context context, AttributeSet attrs) { + super(context, attrs); + } - public ProteusWebView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } + public ProteusWebView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public ProteusWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public ProteusWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } - @Override - public Manager getViewManager() { - return viewManager; - } + @Override + public Manager getViewManager() { + return viewManager; + } - @Override - public void setViewManager(@NonNull Manager manager) { - this.viewManager = manager; - } + @Override + public void setViewManager(@NonNull Manager manager) { + this.viewManager = manager; + } - @NonNull - @Override - public View getAsView() { - return this; - } + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/AspectRatioFrameLayout.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/AspectRatioFrameLayout.java index 3c779aa9..32424a34 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/AspectRatioFrameLayout.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/AspectRatioFrameLayout.java @@ -27,62 +27,62 @@ */ public class AspectRatioFrameLayout extends FrameLayout { - private int mAspectRatioWidth; - private int mAspectRatioHeight; - - public AspectRatioFrameLayout(Context context) { - super(context); - } - - public AspectRatioFrameLayout(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public AspectRatioFrameLayout(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); + private int mAspectRatioWidth; + private int mAspectRatioHeight; + + public AspectRatioFrameLayout(Context context) { + super(context); + } + + public AspectRatioFrameLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public AspectRatioFrameLayout(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public AspectRatioFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + if (mAspectRatioHeight > 0 && mAspectRatioWidth > 0) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + + int originalWidth = getMeasuredWidth(); + + int originalHeight = getMeasuredHeight(); + + int finalWidth, finalHeight; + + if (originalHeight == 0) { + finalHeight = originalWidth * mAspectRatioHeight / mAspectRatioWidth; + finalWidth = originalWidth; + } else if (originalWidth == 0) { + finalWidth = originalHeight * mAspectRatioWidth / mAspectRatioHeight; + finalHeight = originalHeight; + } else { + finalHeight = originalHeight; + finalWidth = originalWidth; + } + + + super.onMeasure( + MeasureSpec.makeMeasureSpec(finalWidth, MeasureSpec.EXACTLY), + MeasureSpec.makeMeasureSpec(finalHeight, MeasureSpec.EXACTLY)); + } else { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); } + } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public AspectRatioFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - if (mAspectRatioHeight > 0 && mAspectRatioWidth > 0) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - - int originalWidth = getMeasuredWidth(); - - int originalHeight = getMeasuredHeight(); + public void setAspectRatioWidth(int mAspectRatioWidth) { + this.mAspectRatioWidth = mAspectRatioWidth; + } - int finalWidth, finalHeight; - - if (originalHeight == 0) { - finalHeight = originalWidth * mAspectRatioHeight / mAspectRatioWidth; - finalWidth = originalWidth; - } else if (originalWidth == 0) { - finalWidth = originalHeight * mAspectRatioWidth / mAspectRatioHeight; - finalHeight = originalHeight; - } else { - finalHeight = originalHeight; - finalWidth = originalWidth; - } - - - super.onMeasure( - MeasureSpec.makeMeasureSpec(finalWidth, MeasureSpec.EXACTLY), - MeasureSpec.makeMeasureSpec(finalHeight, MeasureSpec.EXACTLY)); - } else { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - } - } - - public void setAspectRatioWidth(int mAspectRatioWidth) { - this.mAspectRatioWidth = mAspectRatioWidth; - } - - public void setAspectRatioHeight(int mAspectRatioHeight) { - this.mAspectRatioHeight = mAspectRatioHeight; - } + public void setAspectRatioHeight(int mAspectRatioHeight) { + this.mAspectRatioHeight = mAspectRatioHeight; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/FixedRatingBar.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/FixedRatingBar.java index 287193b9..c448e7bd 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/FixedRatingBar.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/FixedRatingBar.java @@ -39,84 +39,84 @@ * Created by kirankumar on 04/12/14. */ public class FixedRatingBar extends RatingBar { - private Bitmap sampleTile; - - public FixedRatingBar(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public FixedRatingBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } - - public FixedRatingBar(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public FixedRatingBar(Context context) { - super(context); + private Bitmap sampleTile; + + public FixedRatingBar(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public FixedRatingBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + public FixedRatingBar(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public FixedRatingBar(Context context) { + super(context); + } + + public void setSampleTile(Bitmap bitmap) { + this.sampleTile = bitmap; + } + + protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + if (sampleTile != null) { + final int width = sampleTile.getWidth() * getNumStars(); + setMeasuredDimension(resolveSize(width, widthMeasureSpec), getMeasuredHeight()); } + } - public void setSampleTile(Bitmap bitmap) { - this.sampleTile = bitmap; - } - - protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - if (sampleTile != null) { - final int width = sampleTile.getWidth() * getNumStars(); - setMeasuredDimension(resolveSize(width, widthMeasureSpec), getMeasuredHeight()); - } - } + Shape getDrawableShape() { + final float[] roundedCorners = new float[]{5, 5, 5, 5, 5, 5, 5, 5}; + return new RoundRectShape(roundedCorners, null, null); + } - Shape getDrawableShape() { - final float[] roundedCorners = new float[]{5, 5, 5, 5, 5, 5, 5, 5}; - return new RoundRectShape(roundedCorners, null, null); - } + /** + * Taken from AOSP !! + * Converts a drawable to a tiled version of itself. It will recursively + * traverse layer and state list drawables. + */ + public Drawable getTiledDrawable(Drawable drawable, boolean clip) { - /** - * Taken from AOSP !! - * Converts a drawable to a tiled version of itself. It will recursively - * traverse layer and state list drawables. - */ - public Drawable getTiledDrawable(Drawable drawable, boolean clip) { + if (drawable instanceof LayerDrawable) { + LayerDrawable background = (LayerDrawable) drawable; + final int N = background.getNumberOfLayers(); + Drawable[] outDrawables = new Drawable[N]; - if (drawable instanceof LayerDrawable) { - LayerDrawable background = (LayerDrawable) drawable; - final int N = background.getNumberOfLayers(); - Drawable[] outDrawables = new Drawable[N]; + for (int i = 0; i < N; i++) { + int id = background.getId(i); + outDrawables[i] = getTiledDrawable(background.getDrawable(i), + (id == android.R.id.progress || id == android.R.id.secondaryProgress)); + } - for (int i = 0; i < N; i++) { - int id = background.getId(i); - outDrawables[i] = getTiledDrawable(background.getDrawable(i), - (id == android.R.id.progress || id == android.R.id.secondaryProgress)); - } + LayerDrawable newBg = new LayerDrawable(outDrawables); - LayerDrawable newBg = new LayerDrawable(outDrawables); + for (int i = 0; i < N; i++) { + newBg.setId(i, background.getId(i)); + } - for (int i = 0; i < N; i++) { - newBg.setId(i, background.getId(i)); - } + return newBg; - return newBg; + } else if (drawable instanceof BitmapDrawable) { - } else if (drawable instanceof BitmapDrawable) { + final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap(); + if (sampleTile == null) { + sampleTile = tileBitmap; + } + final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape()); - final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap(); - if (sampleTile == null) { - sampleTile = tileBitmap; - } - final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape()); + final BitmapShader bitmapShader = new BitmapShader(tileBitmap, + Shader.TileMode.REPEAT, Shader.TileMode.CLAMP); + shapeDrawable.getPaint().setShader(bitmapShader); - final BitmapShader bitmapShader = new BitmapShader(tileBitmap, - Shader.TileMode.REPEAT, Shader.TileMode.CLAMP); - shapeDrawable.getPaint().setShader(bitmapShader); - - return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT, - ClipDrawable.HORIZONTAL) : shapeDrawable; - } - - return drawable; + return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT, + ClipDrawable.HORIZONTAL) : shapeDrawable; } + + return drawable; + } } diff --git a/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/HorizontalProgressBar.java b/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/HorizontalProgressBar.java index 54590dbb..960a27fa 100644 --- a/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/HorizontalProgressBar.java +++ b/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/HorizontalProgressBar.java @@ -25,7 +25,7 @@ * @author Aditya Sharat */ public class HorizontalProgressBar extends ProgressBar { - public HorizontalProgressBar(Context context) { - super(context, null, android.R.attr.progressBarStyleHorizontal); - } + public HorizontalProgressBar(Context context) { + super(context, null, android.R.attr.progressBarStyleHorizontal); + } } diff --git a/proteus-core/src/test/java/android/graphics/Color.java b/proteus-core/src/test/java/android/graphics/Color.java index ab29f24c..91fa433f 100644 --- a/proteus-core/src/test/java/android/graphics/Color.java +++ b/proteus-core/src/test/java/android/graphics/Color.java @@ -32,67 +32,67 @@ * 0xFFFFFFFF */ public class Color { - public static final int BLACK = 0xFF000000; - public static final int DKGRAY = 0xFF444444; - public static final int GRAY = 0xFF888888; - public static final int LTGRAY = 0xFFCCCCCC; - public static final int WHITE = 0xFFFFFFFF; - public static final int RED = 0xFFFF0000; - public static final int GREEN = 0xFF00FF00; - public static final int BLUE = 0xFF0000FF; - public static final int YELLOW = 0xFFFFFF00; - public static final int CYAN = 0xFF00FFFF; - public static final int MAGENTA = 0xFFFF00FF; - public static final int TRANSPARENT = 0; + public static final int BLACK = 0xFF000000; + public static final int DKGRAY = 0xFF444444; + public static final int GRAY = 0xFF888888; + public static final int LTGRAY = 0xFFCCCCCC; + public static final int WHITE = 0xFFFFFFFF; + public static final int RED = 0xFFFF0000; + public static final int GREEN = 0xFF00FF00; + public static final int BLUE = 0xFF0000FF; + public static final int YELLOW = 0xFFFFFF00; + public static final int CYAN = 0xFF00FFFF; + public static final int MAGENTA = 0xFFFF00FF; + public static final int TRANSPARENT = 0; - public static int parseColor(String colorString) { - if (colorString.charAt(0) == '#') { - // Use a long to avoid rollovers on #ffXXXXXX - long color = Long.parseLong(colorString.substring(1), 16); - if (colorString.length() == 7) { - // Set the alpha value - color |= 0x00000000ff000000; - } else if (colorString.length() != 9) { - throw new IllegalArgumentException("Unknown color"); - } - return (int) color; - } else { - Integer color = sColorNameMap.get(colorString.toLowerCase(Locale.ROOT)); - if (color != null) { - return color; - } - } + public static int parseColor(String colorString) { + if (colorString.charAt(0) == '#') { + // Use a long to avoid rollovers on #ffXXXXXX + long color = Long.parseLong(colorString.substring(1), 16); + if (colorString.length() == 7) { + // Set the alpha value + color |= 0x00000000ff000000; + } else if (colorString.length() != 9) { throw new IllegalArgumentException("Unknown color"); + } + return (int) color; + } else { + Integer color = sColorNameMap.get(colorString.toLowerCase(Locale.ROOT)); + if (color != null) { + return color; + } } + throw new IllegalArgumentException("Unknown color"); + } - private static final HashMap sColorNameMap; + private static final HashMap sColorNameMap; - static { - sColorNameMap = new HashMap(); - sColorNameMap.put("black", BLACK); - sColorNameMap.put("darkgray", DKGRAY); - sColorNameMap.put("gray", GRAY); - sColorNameMap.put("lightgray", LTGRAY); - sColorNameMap.put("white", WHITE); - sColorNameMap.put("red", RED); - sColorNameMap.put("green", GREEN); - sColorNameMap.put("blue", BLUE); - sColorNameMap.put("yellow", YELLOW); - sColorNameMap.put("cyan", CYAN); - sColorNameMap.put("magenta", MAGENTA); - sColorNameMap.put("aqua", 0xFF00FFFF); - sColorNameMap.put("fuchsia", 0xFFFF00FF); - sColorNameMap.put("darkgrey", DKGRAY); - sColorNameMap.put("grey", GRAY); - sColorNameMap.put("lightgrey", LTGRAY); - sColorNameMap.put("lime", 0xFF00FF00); - sColorNameMap.put("maroon", 0xFF800000); - sColorNameMap.put("navy", 0xFF000080); - sColorNameMap.put("olive", 0xFF808000); - sColorNameMap.put("purple", 0xFF800080); - sColorNameMap.put("silver", 0xFFC0C0C0); - sColorNameMap.put("teal", 0xFF008080); + static { + sColorNameMap = new HashMap(); + sColorNameMap.put("black", BLACK); + sColorNameMap.put("darkgray", DKGRAY); + sColorNameMap.put("gray", GRAY); + sColorNameMap.put("lightgray", LTGRAY); + sColorNameMap.put("white", WHITE); + sColorNameMap.put("red", RED); + sColorNameMap.put("green", GREEN); + sColorNameMap.put("blue", BLUE); + sColorNameMap.put("yellow", YELLOW); + sColorNameMap.put("cyan", CYAN); + sColorNameMap.put("magenta", MAGENTA); + sColorNameMap.put("aqua", 0xFF00FFFF); + sColorNameMap.put("fuchsia", 0xFFFF00FF); + sColorNameMap.put("darkgrey", DKGRAY); + sColorNameMap.put("grey", GRAY); + sColorNameMap.put("lightgrey", LTGRAY); + sColorNameMap.put("lime", 0xFF00FF00); + sColorNameMap.put("maroon", 0xFF800000); + sColorNameMap.put("navy", 0xFF000080); + sColorNameMap.put("olive", 0xFF808000); + sColorNameMap.put("purple", 0xFF800080); + sColorNameMap.put("silver", 0xFFC0C0C0); + sColorNameMap.put("teal", 0xFF008080); - } + } } diff --git a/proteus-core/src/test/java/android/util/LruCache.java b/proteus-core/src/test/java/android/util/LruCache.java index e4b3ce00..0120ff37 100644 --- a/proteus-core/src/test/java/android/util/LruCache.java +++ b/proteus-core/src/test/java/android/util/LruCache.java @@ -62,299 +62,299 @@ *

*/ public class LruCache { - private final LinkedHashMap map; - - /** - * Size of this cache in units. Not necessarily the number of elements. - */ - private int size; - private int maxSize; - - private int putCount; - private int createCount; - private int evictionCount; - private int hitCount; - private int missCount; - - /** - * @param maxSize for caches that do not override {@link #sizeOf}, this is - * the maximum number of entries in the cache. For all other caches, - * this is the maximum sum of the sizes of the entries in this cache. - */ - public LruCache(int maxSize) { - if (maxSize <= 0) { - throw new IllegalArgumentException("maxSize <= 0"); - } - this.maxSize = maxSize; - this.map = new LinkedHashMap(0, 0.75f, true); + private final LinkedHashMap map; + + /** + * Size of this cache in units. Not necessarily the number of elements. + */ + private int size; + private int maxSize; + + private int putCount; + private int createCount; + private int evictionCount; + private int hitCount; + private int missCount; + + /** + * @param maxSize for caches that do not override {@link #sizeOf}, this is + * the maximum number of entries in the cache. For all other caches, + * this is the maximum sum of the sizes of the entries in this cache. + */ + public LruCache(int maxSize) { + if (maxSize <= 0) { + throw new IllegalArgumentException("maxSize <= 0"); } - - /** - * Sets the size of the cache. - * - * @param maxSize The new maximum size. - */ - public void resize(int maxSize) { - if (maxSize <= 0) { - throw new IllegalArgumentException("maxSize <= 0"); - } - - synchronized (this) { - this.maxSize = maxSize; - } - trimToSize(maxSize); + this.maxSize = maxSize; + this.map = new LinkedHashMap(0, 0.75f, true); + } + + /** + * Sets the size of the cache. + * + * @param maxSize The new maximum size. + */ + public void resize(int maxSize) { + if (maxSize <= 0) { + throw new IllegalArgumentException("maxSize <= 0"); } - /** - * Returns the value for {@code key} if it exists in the cache or can be - * created by {@code #create}. If a value was returned, it is moved to the - * head of the queue. This returns null if a value is not cached and cannot - * be created. - */ - public final V get(K key) { - if (key == null) { - throw new NullPointerException("key == null"); - } - - V mapValue; - synchronized (this) { - mapValue = map.get(key); - if (mapValue != null) { - hitCount++; - return mapValue; - } - missCount++; - } - - /* - * Attempt to create a value. This may take a long time, and the map - * may be different when create() returns. If a conflicting value was - * added to the map while create() was working, we leave that value in - * the map and release the created value. - */ - - V createdValue = create(key); - if (createdValue == null) { - return null; - } - - synchronized (this) { - createCount++; - mapValue = map.put(key, createdValue); - - if (mapValue != null) { - // There was a conflict so undo that last put - map.put(key, mapValue); - } else { - size += safeSizeOf(key, createdValue); - } - } - - if (mapValue != null) { - entryRemoved(false, key, createdValue, mapValue); - return mapValue; - } else { - trimToSize(maxSize); - return createdValue; - } + synchronized (this) { + this.maxSize = maxSize; } - - /** - * Caches {@code value} for {@code key}. The value is moved to the head of - * the queue. - * - * @return the previous value mapped by {@code key}. - */ - public final V put(K key, V value) { - if (key == null || value == null) { - throw new NullPointerException("key == null || value == null"); - } - - V previous; - synchronized (this) { - putCount++; - size += safeSizeOf(key, value); - previous = map.put(key, value); - if (previous != null) { - size -= safeSizeOf(key, previous); - } - } - - if (previous != null) { - entryRemoved(false, key, previous, value); - } - - trimToSize(maxSize); - return previous; + trimToSize(maxSize); + } + + /** + * Returns the value for {@code key} if it exists in the cache or can be + * created by {@code #create}. If a value was returned, it is moved to the + * head of the queue. This returns null if a value is not cached and cannot + * be created. + */ + public final V get(K key) { + if (key == null) { + throw new NullPointerException("key == null"); } - /** - * Remove the eldest entries until the total of remaining entries is at or - * below the requested size. - * - * @param maxSize the maximum size of the cache before returning. May be -1 - * to evict even 0-sized elements. - */ - public void trimToSize(int maxSize) { - + V mapValue; + synchronized (this) { + mapValue = map.get(key); + if (mapValue != null) { + hitCount++; + return mapValue; + } + missCount++; } - /** - * Removes the entry for {@code key} if it exists. - * - * @return the previous value mapped by {@code key}. + /* + * Attempt to create a value. This may take a long time, and the map + * may be different when create() returns. If a conflicting value was + * added to the map while create() was working, we leave that value in + * the map and release the created value. */ - public final V remove(K key) { - if (key == null) { - throw new NullPointerException("key == null"); - } - - V previous; - synchronized (this) { - previous = map.remove(key); - if (previous != null) { - size -= safeSizeOf(key, previous); - } - } - - if (previous != null) { - entryRemoved(false, key, previous, null); - } - - return previous; - } - /** - * Called for entries that have been evicted or removed. This method is - * invoked when a value is evicted to make space, removed by a call to - * {@link #remove}, or replaced by a call to {@link #put}. The default - * implementation does nothing. - *

- *

The method is called without synchronization: other threads may - * access the cache while this method is executing. - * - * @param evicted true if the entry is being removed to make space, false - * if the removal was caused by a {@link #put} or {@link #remove}. - * @param newValue the new value for {@code key}, if it exists. If non-null, - * this removal was caused by a {@link #put}. Otherwise it was caused by - * an eviction or a {@link #remove}. - */ - protected void entryRemoved(boolean evicted, K key, V oldValue, V newValue) { + V createdValue = create(key); + if (createdValue == null) { + return null; } - /** - * Called after a cache miss to compute a value for the corresponding key. - * Returns the computed value or null if no value can be computed. The - * default implementation returns null. - *

- *

The method is called without synchronization: other threads may - * access the cache while this method is executing. - *

- *

If a value for {@code key} exists in the cache when this method - * returns, the created value will be released with {@link #entryRemoved} - * and discarded. This can occur when multiple threads request the same key - * at the same time (causing multiple values to be created), or when one - * thread calls {@link #put} while another is creating a value for the same - * key. - */ - protected V create(K key) { - return null; - } + synchronized (this) { + createCount++; + mapValue = map.put(key, createdValue); - private int safeSizeOf(K key, V value) { - int result = sizeOf(key, value); - if (result < 0) { - throw new IllegalStateException("Negative size: " + key + "=" + value); - } - return result; + if (mapValue != null) { + // There was a conflict so undo that last put + map.put(key, mapValue); + } else { + size += safeSizeOf(key, createdValue); + } } - /** - * Returns the size of the entry for {@code key} and {@code value} in - * user-defined units. The default implementation returns 1 so that size - * is the number of entries and max size is the maximum number of entries. - *

- *

An entry's size must not change while it is in the cache. - */ - protected int sizeOf(K key, V value) { - return 1; + if (mapValue != null) { + entryRemoved(false, key, createdValue, mapValue); + return mapValue; + } else { + trimToSize(maxSize); + return createdValue; } - - /** - * Clear the cache, calling {@link #entryRemoved} on each removed entry. - */ - public final void evictAll() { - trimToSize(-1); // -1 will evict 0-sized elements - } - - /** - * For caches that do not override {@link #sizeOf}, this returns the number - * of entries in the cache. For all other caches, this returns the sum of - * the sizes of the entries in this cache. - */ - public synchronized final int size() { - return size; + } + + /** + * Caches {@code value} for {@code key}. The value is moved to the head of + * the queue. + * + * @return the previous value mapped by {@code key}. + */ + public final V put(K key, V value) { + if (key == null || value == null) { + throw new NullPointerException("key == null || value == null"); } - /** - * For caches that do not override {@link #sizeOf}, this returns the maximum - * number of entries in the cache. For all other caches, this returns the - * maximum sum of the sizes of the entries in this cache. - */ - public synchronized final int maxSize() { - return maxSize; + V previous; + synchronized (this) { + putCount++; + size += safeSizeOf(key, value); + previous = map.put(key, value); + if (previous != null) { + size -= safeSizeOf(key, previous); + } } - /** - * Returns the number of times {@link #get} returned a value that was - * already present in the cache. - */ - public synchronized final int hitCount() { - return hitCount; + if (previous != null) { + entryRemoved(false, key, previous, value); } - /** - * Returns the number of times {@link #get} returned null or required a new - * value to be created. - */ - public synchronized final int missCount() { - return missCount; + trimToSize(maxSize); + return previous; + } + + /** + * Remove the eldest entries until the total of remaining entries is at or + * below the requested size. + * + * @param maxSize the maximum size of the cache before returning. May be -1 + * to evict even 0-sized elements. + */ + public void trimToSize(int maxSize) { + + } + + /** + * Removes the entry for {@code key} if it exists. + * + * @return the previous value mapped by {@code key}. + */ + public final V remove(K key) { + if (key == null) { + throw new NullPointerException("key == null"); } - /** - * Returns the number of times {@link #create(Object)} returned a value. - */ - public synchronized final int createCount() { - return createCount; + V previous; + synchronized (this) { + previous = map.remove(key); + if (previous != null) { + size -= safeSizeOf(key, previous); + } } - /** - * Returns the number of times {@link #put} was called. - */ - public synchronized final int putCount() { - return putCount; - } - - /** - * Returns the number of values that have been evicted. - */ - public synchronized final int evictionCount() { - return evictionCount; - } - - /** - * Returns a copy of the current contents of the cache, ordered from least - * recently accessed to most recently accessed. - */ - public synchronized final Map snapshot() { - return new LinkedHashMap(map); + if (previous != null) { + entryRemoved(false, key, previous, null); } - @Override - public synchronized final String toString() { - int accesses = hitCount + missCount; - int hitPercent = accesses != 0 ? (100 * hitCount / accesses) : 0; - return String.format("LruCache[maxSize=%d,hits=%d,misses=%d,hitRate=%d%%]", - maxSize, hitCount, missCount, hitPercent); + return previous; + } + + /** + * Called for entries that have been evicted or removed. This method is + * invoked when a value is evicted to make space, removed by a call to + * {@link #remove}, or replaced by a call to {@link #put}. The default + * implementation does nothing. + *

+ *

The method is called without synchronization: other threads may + * access the cache while this method is executing. + * + * @param evicted true if the entry is being removed to make space, false + * if the removal was caused by a {@link #put} or {@link #remove}. + * @param newValue the new value for {@code key}, if it exists. If non-null, + * this removal was caused by a {@link #put}. Otherwise it was caused by + * an eviction or a {@link #remove}. + */ + protected void entryRemoved(boolean evicted, K key, V oldValue, V newValue) { + } + + /** + * Called after a cache miss to compute a value for the corresponding key. + * Returns the computed value or null if no value can be computed. The + * default implementation returns null. + *

+ *

The method is called without synchronization: other threads may + * access the cache while this method is executing. + *

+ *

If a value for {@code key} exists in the cache when this method + * returns, the created value will be released with {@link #entryRemoved} + * and discarded. This can occur when multiple threads request the same key + * at the same time (causing multiple values to be created), or when one + * thread calls {@link #put} while another is creating a value for the same + * key. + */ + protected V create(K key) { + return null; + } + + private int safeSizeOf(K key, V value) { + int result = sizeOf(key, value); + if (result < 0) { + throw new IllegalStateException("Negative size: " + key + "=" + value); } + return result; + } + + /** + * Returns the size of the entry for {@code key} and {@code value} in + * user-defined units. The default implementation returns 1 so that size + * is the number of entries and max size is the maximum number of entries. + *

+ *

An entry's size must not change while it is in the cache. + */ + protected int sizeOf(K key, V value) { + return 1; + } + + /** + * Clear the cache, calling {@link #entryRemoved} on each removed entry. + */ + public final void evictAll() { + trimToSize(-1); // -1 will evict 0-sized elements + } + + /** + * For caches that do not override {@link #sizeOf}, this returns the number + * of entries in the cache. For all other caches, this returns the sum of + * the sizes of the entries in this cache. + */ + public synchronized final int size() { + return size; + } + + /** + * For caches that do not override {@link #sizeOf}, this returns the maximum + * number of entries in the cache. For all other caches, this returns the + * maximum sum of the sizes of the entries in this cache. + */ + public synchronized final int maxSize() { + return maxSize; + } + + /** + * Returns the number of times {@link #get} returned a value that was + * already present in the cache. + */ + public synchronized final int hitCount() { + return hitCount; + } + + /** + * Returns the number of times {@link #get} returned null or required a new + * value to be created. + */ + public synchronized final int missCount() { + return missCount; + } + + /** + * Returns the number of times {@link #create(Object)} returned a value. + */ + public synchronized final int createCount() { + return createCount; + } + + /** + * Returns the number of times {@link #put} was called. + */ + public synchronized final int putCount() { + return putCount; + } + + /** + * Returns the number of values that have been evicted. + */ + public synchronized final int evictionCount() { + return evictionCount; + } + + /** + * Returns a copy of the current contents of the cache, ordered from least + * recently accessed to most recently accessed. + */ + public synchronized final Map snapshot() { + return new LinkedHashMap(map); + } + + @Override + public synchronized final String toString() { + int accesses = hitCount + missCount; + int hitPercent = accesses != 0 ? (100 * hitCount / accesses) : 0; + return String.format("LruCache[maxSize=%d,hits=%d,misses=%d,hitRate=%d%%]", + maxSize, hitCount, missCount, hitPercent); + } } diff --git a/proteus-core/src/test/java/android/util/TypedValue.java b/proteus-core/src/test/java/android/util/TypedValue.java index bb9710fd..86891450 100644 --- a/proteus-core/src/test/java/android/util/TypedValue.java +++ b/proteus-core/src/test/java/android/util/TypedValue.java @@ -25,7 +25,7 @@ */ public class TypedValue { - public static float applyDimension(int unit, float value, DisplayMetrics metrics) { - return value; - } + public static float applyDimension(int unit, float value, DisplayMetrics metrics) { + return value; + } } diff --git a/proteus-core/src/test/java/com/flipkart/android/proteus/parser/ParseHelperTest.java b/proteus-core/src/test/java/com/flipkart/android/proteus/parser/ParseHelperTest.java index c6fdec4d..7a8dc279 100644 --- a/proteus-core/src/test/java/com/flipkart/android/proteus/parser/ParseHelperTest.java +++ b/proteus-core/src/test/java/com/flipkart/android/proteus/parser/ParseHelperTest.java @@ -26,31 +26,31 @@ */ public class ParseHelperTest { - @Test - public void testParseInt() { - String input; + @Test + public void testParseInt() { + String input; - // check 0 - input = "0"; - Assert.assertEquals(ParseHelper.parseInt(input), 0); + // check 0 + input = "0"; + Assert.assertEquals(ParseHelper.parseInt(input), 0); - // check negative - input = "-1"; - Assert.assertEquals(ParseHelper.parseInt(input), -1); + // check negative + input = "-1"; + Assert.assertEquals(ParseHelper.parseInt(input), -1); - // check positive - input = "1"; - Assert.assertEquals(ParseHelper.parseInt(input), 1); + // check positive + input = "1"; + Assert.assertEquals(ParseHelper.parseInt(input), 1); - // check null - Assert.assertEquals(ParseHelper.parseInt(null), 0); + // check null + Assert.assertEquals(ParseHelper.parseInt(null), 0); - // check "null" - input = "null"; - Assert.assertEquals(ParseHelper.parseInt(input), 0); + // check "null" + input = "null"; + Assert.assertEquals(ParseHelper.parseInt(input), 0); - // check random string - input = "blah blah"; - Assert.assertEquals(ParseHelper.parseInt(input), 0); - } + // check random string + input = "blah blah"; + Assert.assertEquals(ParseHelper.parseInt(input), 0); + } } \ No newline at end of file diff --git a/proteus-core/src/test/java/com/flipkart/android/proteus/processor/GravityAttributeProcessorTest.java b/proteus-core/src/test/java/com/flipkart/android/proteus/processor/GravityAttributeProcessorTest.java index c8547715..73ecdb34 100644 --- a/proteus-core/src/test/java/com/flipkart/android/proteus/processor/GravityAttributeProcessorTest.java +++ b/proteus-core/src/test/java/com/flipkart/android/proteus/processor/GravityAttributeProcessorTest.java @@ -37,129 +37,129 @@ */ public class GravityAttributeProcessorTest { - @Test - public void parse_simple() throws Exception { - String CENTER = "center"; - String CENTER_HORIZONTAL = "center_horizontal"; - String CENTER_VERTICAL = "center_vertical"; - String LEFT = "left"; - String RIGHT = "right"; - String TOP = "top"; - String BOTTOM = "bottom"; - String START = "start"; - String END = "end"; - - Map sGravityMap = new HashMap<>(); - - sGravityMap.put(CENTER, Gravity.CENTER); - sGravityMap.put(CENTER_HORIZONTAL, Gravity.CENTER_HORIZONTAL); - sGravityMap.put(CENTER_VERTICAL, Gravity.CENTER_VERTICAL); - sGravityMap.put(LEFT, Gravity.LEFT); - sGravityMap.put(RIGHT, Gravity.RIGHT); - sGravityMap.put(TOP, Gravity.TOP); - sGravityMap.put(BOTTOM, Gravity.BOTTOM); - sGravityMap.put(START, Gravity.START); - sGravityMap.put(END, Gravity.END); - - AttributeProcessor processor = new GravityAttributeProcessor() { - @Override - public void setGravity(View view, @Gravity int gravity) { - - } - }; - - for (Map.Entry entry : sGravityMap.entrySet()) { - System.out.print("\nGravityAttributeProcessorTest:parse_simple() when gravity : '" + entry.getKey() + "'\n"); - Value value = processor.compile(new Primitive(entry.getKey()), null); - assertThat(value.getAsInt(), is(entry.getValue())); - } + @Test + public void parse_simple() throws Exception { + String CENTER = "center"; + String CENTER_HORIZONTAL = "center_horizontal"; + String CENTER_VERTICAL = "center_vertical"; + String LEFT = "left"; + String RIGHT = "right"; + String TOP = "top"; + String BOTTOM = "bottom"; + String START = "start"; + String END = "end"; + + Map sGravityMap = new HashMap<>(); + + sGravityMap.put(CENTER, Gravity.CENTER); + sGravityMap.put(CENTER_HORIZONTAL, Gravity.CENTER_HORIZONTAL); + sGravityMap.put(CENTER_VERTICAL, Gravity.CENTER_VERTICAL); + sGravityMap.put(LEFT, Gravity.LEFT); + sGravityMap.put(RIGHT, Gravity.RIGHT); + sGravityMap.put(TOP, Gravity.TOP); + sGravityMap.put(BOTTOM, Gravity.BOTTOM); + sGravityMap.put(START, Gravity.START); + sGravityMap.put(END, Gravity.END); + + AttributeProcessor processor = new GravityAttributeProcessor() { + @Override + public void setGravity(View view, @Gravity int gravity) { + + } + }; + + for (Map.Entry entry : sGravityMap.entrySet()) { + System.out.print("\nGravityAttributeProcessorTest:parse_simple() when gravity : '" + entry.getKey() + "'\n"); + Value value = processor.compile(new Primitive(entry.getKey()), null); + assertThat(value.getAsInt(), is(entry.getValue())); } - - @Test - public void parse_complex() throws Exception { - AttributeProcessor processor = new GravityAttributeProcessor() { - @Override - public void setGravity(View view, @Gravity int gravity) { - - } - }; - - Value value = processor.compile(new Primitive("top|left"), null); - int gravity = Gravity.TOP | Gravity.LEFT; - assertThat(value.getAsInt(), is(gravity)); - } - - @Test - public void handle_string() throws Exception { - String CENTER = "center"; - String CENTER_HORIZONTAL = "center_horizontal"; - String CENTER_VERTICAL = "center_vertical"; - String LEFT = "left"; - String RIGHT = "right"; - String TOP = "top"; - String BOTTOM = "bottom"; - String START = "start"; - String END = "end"; - - Map sGravityMap = new HashMap<>(); - - sGravityMap.put(CENTER, Gravity.CENTER); - sGravityMap.put(CENTER_HORIZONTAL, Gravity.CENTER_HORIZONTAL); - sGravityMap.put(CENTER_VERTICAL, Gravity.CENTER_VERTICAL); - sGravityMap.put(LEFT, Gravity.LEFT); - sGravityMap.put(RIGHT, Gravity.RIGHT); - sGravityMap.put(TOP, Gravity.TOP); - sGravityMap.put(BOTTOM, Gravity.BOTTOM); - sGravityMap.put(START, Gravity.START); - sGravityMap.put(END, Gravity.END); - - for (final Map.Entry entry : sGravityMap.entrySet()) { - System.out.print("\nGravityAttributeProcessorTest:handle_string() when gravity : '" + entry.getKey() + "'\n"); - AttributeProcessor processor = new GravityAttributeProcessor() { - @Override - public void setGravity(View view, @Gravity int gravity) { - assertThat(gravity, is(entry.getValue())); - } - }; - processor.handleValue(null, new Primitive(entry.getKey())); + } + + @Test + public void parse_complex() throws Exception { + AttributeProcessor processor = new GravityAttributeProcessor() { + @Override + public void setGravity(View view, @Gravity int gravity) { + + } + }; + + Value value = processor.compile(new Primitive("top|left"), null); + int gravity = Gravity.TOP | Gravity.LEFT; + assertThat(value.getAsInt(), is(gravity)); + } + + @Test + public void handle_string() throws Exception { + String CENTER = "center"; + String CENTER_HORIZONTAL = "center_horizontal"; + String CENTER_VERTICAL = "center_vertical"; + String LEFT = "left"; + String RIGHT = "right"; + String TOP = "top"; + String BOTTOM = "bottom"; + String START = "start"; + String END = "end"; + + Map sGravityMap = new HashMap<>(); + + sGravityMap.put(CENTER, Gravity.CENTER); + sGravityMap.put(CENTER_HORIZONTAL, Gravity.CENTER_HORIZONTAL); + sGravityMap.put(CENTER_VERTICAL, Gravity.CENTER_VERTICAL); + sGravityMap.put(LEFT, Gravity.LEFT); + sGravityMap.put(RIGHT, Gravity.RIGHT); + sGravityMap.put(TOP, Gravity.TOP); + sGravityMap.put(BOTTOM, Gravity.BOTTOM); + sGravityMap.put(START, Gravity.START); + sGravityMap.put(END, Gravity.END); + + for (final Map.Entry entry : sGravityMap.entrySet()) { + System.out.print("\nGravityAttributeProcessorTest:handle_string() when gravity : '" + entry.getKey() + "'\n"); + AttributeProcessor processor = new GravityAttributeProcessor() { + @Override + public void setGravity(View view, @Gravity int gravity) { + assertThat(gravity, is(entry.getValue())); } + }; + processor.handleValue(null, new Primitive(entry.getKey())); } - - @Test - public void handle_gravity() throws Exception { - String CENTER = "center"; - String CENTER_HORIZONTAL = "center_horizontal"; - String CENTER_VERTICAL = "center_vertical"; - String LEFT = "left"; - String RIGHT = "right"; - String TOP = "top"; - String BOTTOM = "bottom"; - String START = "start"; - String END = "end"; - - Map sGravityMap = new HashMap<>(); - - sGravityMap.put(CENTER, Gravity.CENTER); - sGravityMap.put(CENTER_HORIZONTAL, Gravity.CENTER_HORIZONTAL); - sGravityMap.put(CENTER_VERTICAL, Gravity.CENTER_VERTICAL); - sGravityMap.put(LEFT, Gravity.LEFT); - sGravityMap.put(RIGHT, Gravity.RIGHT); - sGravityMap.put(TOP, Gravity.TOP); - sGravityMap.put(BOTTOM, Gravity.BOTTOM); - sGravityMap.put(START, Gravity.START); - sGravityMap.put(END, Gravity.END); - - for (final Map.Entry entry : sGravityMap.entrySet()) { - System.out.print("\nGravityAttributeProcessorTest:handle_gravity() when gravity : '" + entry.getKey() + "'\n"); - AttributeProcessor processor = new GravityAttributeProcessor() { - @Override - public void setGravity(View view, @Gravity int gravity) { - assertThat(gravity, is(entry.getValue())); - } - }; - Value value = processor.compile(new Primitive(entry.getKey()), null); - processor.handleValue(null, value); + } + + @Test + public void handle_gravity() throws Exception { + String CENTER = "center"; + String CENTER_HORIZONTAL = "center_horizontal"; + String CENTER_VERTICAL = "center_vertical"; + String LEFT = "left"; + String RIGHT = "right"; + String TOP = "top"; + String BOTTOM = "bottom"; + String START = "start"; + String END = "end"; + + Map sGravityMap = new HashMap<>(); + + sGravityMap.put(CENTER, Gravity.CENTER); + sGravityMap.put(CENTER_HORIZONTAL, Gravity.CENTER_HORIZONTAL); + sGravityMap.put(CENTER_VERTICAL, Gravity.CENTER_VERTICAL); + sGravityMap.put(LEFT, Gravity.LEFT); + sGravityMap.put(RIGHT, Gravity.RIGHT); + sGravityMap.put(TOP, Gravity.TOP); + sGravityMap.put(BOTTOM, Gravity.BOTTOM); + sGravityMap.put(START, Gravity.START); + sGravityMap.put(END, Gravity.END); + + for (final Map.Entry entry : sGravityMap.entrySet()) { + System.out.print("\nGravityAttributeProcessorTest:handle_gravity() when gravity : '" + entry.getKey() + "'\n"); + AttributeProcessor processor = new GravityAttributeProcessor() { + @Override + public void setGravity(View view, @Gravity int gravity) { + assertThat(gravity, is(entry.getValue())); } + }; + Value value = processor.compile(new Primitive(entry.getKey()), null); + processor.handleValue(null, value); } + } } \ No newline at end of file diff --git a/proteus-core/src/test/java/com/flipkart/android/proteus/value/BindingTest.java b/proteus-core/src/test/java/com/flipkart/android/proteus/value/BindingTest.java index 1a107e6f..cf39e981 100644 --- a/proteus-core/src/test/java/com/flipkart/android/proteus/value/BindingTest.java +++ b/proteus-core/src/test/java/com/flipkart/android/proteus/value/BindingTest.java @@ -35,428 +35,428 @@ */ public class BindingTest { - /* - * { - * "a" : { - * "b": { - * "c": 10, - * "d": true - * } - * } - * "e": ["alpha", 2, false], - * "f": null - * } - * - */ - public static ObjectValue data() { - ObjectValue object = new ObjectValue(); - - ObjectValue a = new ObjectValue(); - ObjectValue b = new ObjectValue(); - Primitive c = new Primitive(10); - Primitive d = new Primitive(true); - Array e = new Array(); - e.add(new Primitive("alpha")); - e.add(new Primitive(2)); - e.add(new Primitive(false)); - - b.add("c", c); - b.add("d", d); - a.add("b", b); - object.add("a", a); - object.add("e", e); - object.add("f", Null.INSTANCE); - object.add("g", new Array()); - - return object; - } - - public static ProteusContext context() { - Proteus proteus = new ProteusBuilder().build(); - Context context = mock(Context.class); - return proteus.createContextBuilder(context).build(); - } - - @Test - public void is_binding_1() throws Exception { - assertThat(Binding.isBindingValue("@{a.b.c}"), is(true)); - } + /* + * { + * "a" : { + * "b": { + * "c": 10, + * "d": true + * } + * } + * "e": ["alpha", 2, false], + * "f": null + * } + * + */ + public static ObjectValue data() { + ObjectValue object = new ObjectValue(); + + ObjectValue a = new ObjectValue(); + ObjectValue b = new ObjectValue(); + Primitive c = new Primitive(10); + Primitive d = new Primitive(true); + Array e = new Array(); + e.add(new Primitive("alpha")); + e.add(new Primitive(2)); + e.add(new Primitive(false)); + + b.add("c", c); + b.add("d", d); + a.add("b", b); + object.add("a", a); + object.add("e", e); + object.add("f", Null.INSTANCE); + object.add("g", new Array()); + + return object; + } + + public static ProteusContext context() { + Proteus proteus = new ProteusBuilder().build(); + Context context = mock(Context.class); + return proteus.createContextBuilder(context).build(); + } + + @Test + public void is_binding_1() throws Exception { + assertThat(Binding.isBindingValue("@{a.b.c}"), is(true)); + } + + @Test + public void is_not_binding() throws Exception { + assertThat(Binding.isBindingValue("a.b.c"), is(false)); + assertThat(Binding.isBindingValue("@{"), is(false)); + assertThat(Binding.isBindingValue("@}"), is(false)); + } + + @Test + public void evaluate_not_binding() throws Exception { + try { + Binding.valueOf("abc", null, null); + } catch (IllegalArgumentException e) { + assertThat(true, is(true)); + } + } - @Test - public void is_not_binding() throws Exception { - assertThat(Binding.isBindingValue("a.b.c"), is(false)); - assertThat(Binding.isBindingValue("@{"), is(false)); - assertThat(Binding.isBindingValue("@}"), is(false)); - } - - @Test - public void evaluate_not_binding() throws Exception { - try { - Binding.valueOf("abc", null, null); - } catch (IllegalArgumentException e) { - assertThat(true, is(true)); - } - } + @Test + public void evaluate_binding() throws Exception { + Binding binding = Binding.valueOf("@{a.b.c}", null, null); - @Test - public void evaluate_binding() throws Exception { - Binding binding = Binding.valueOf("@{a.b.c}", null, null); + Value value = binding.evaluate(null, data(), 0); - Value value = binding.evaluate(null, data(), 0); - - assertThat(value.getAsString(), is("10")); - } + assertThat(value.getAsString(), is("10")); + } - @Test - public void evaluate_function() throws Exception { - ProteusContext context = context(); - Binding binding = Binding.valueOf("@{fn:add(1,1)}", context, context.getFunctionManager()); + @Test + public void evaluate_function() throws Exception { + ProteusContext context = context(); + Binding binding = Binding.valueOf("@{fn:add(1,1)}", context, context.getFunctionManager()); - Value value = binding.evaluate(null, data(), 0); + Value value = binding.evaluate(null, data(), 0); - assertThat(value.getAsString(), is("2.0")); - } + assertThat(value.getAsString(), is("2.0")); + } - @Test - public void to_string_1() throws Exception { - String string = "@{a.b.c}"; - Binding binding = Binding.valueOf(string, null, null); + @Test + public void to_string_1() throws Exception { + String string = "@{a.b.c}"; + Binding binding = Binding.valueOf(string, null, null); - assertThat(binding.toString(), is(string)); - } + assertThat(binding.toString(), is(string)); + } - @Test - public void to_string_2() throws Exception { - ProteusContext context = context(); - String string = "@{fn:add('1','1')}"; - Binding binding = Binding.valueOf(string, context, context.getFunctionManager()); + @Test + public void to_string_2() throws Exception { + ProteusContext context = context(); + String string = "@{fn:add('1','1')}"; + Binding binding = Binding.valueOf(string, context, context.getFunctionManager()); - assertThat(binding.toString(), is(string)); - } + assertThat(binding.toString(), is(string)); + } - @Test - public void copy() throws Exception { - Binding binding = Binding.valueOf("@{a.b.c}", null, null); + @Test + public void copy() throws Exception { + Binding binding = Binding.valueOf("@{a.b.c}", null, null); - assertThat(binding, is(binding.copy())); - } + assertThat(binding, is(binding.copy())); + } - @Test - public void evaluate_null_1() throws Exception { - Binding binding = Binding.valueOf("@{a.b.c}", null, null); + @Test + public void evaluate_null_1() throws Exception { + Binding binding = Binding.valueOf("@{a.b.c}", null, null); - ObjectValue data = data(); - ((Binding.DataBinding) binding).assign(Null.INSTANCE, data, 0); + ObjectValue data = data(); + ((Binding.DataBinding) binding).assign(Null.INSTANCE, data, 0); - Value value = binding.evaluate(null, data, 0); + Value value = binding.evaluate(null, data, 0); - assertThat(value.toString(), is("NULL")); - } + assertThat(value.toString(), is("NULL")); + } - @Test - public void evaluate_null_2() throws Exception { - Binding binding = Binding.valueOf("@{a.b.c.d}", null, null); + @Test + public void evaluate_null_2() throws Exception { + Binding binding = Binding.valueOf("@{a.b.c.d}", null, null); - Value value = binding.evaluate(null, data(), 0); + Value value = binding.evaluate(null, data(), 0); - assertThat(value.toString(), is("NULL")); - } + assertThat(value.toString(), is("NULL")); + } - @Test - public void evaluate_null_3() throws Exception { - Binding binding = Binding.valueOf("@{a.b[0]}", null, null); + @Test + public void evaluate_null_3() throws Exception { + Binding binding = Binding.valueOf("@{a.b[0]}", null, null); - Value value = binding.evaluate(null, data(), 0); + Value value = binding.evaluate(null, data(), 0); - assertThat(value.toString(), is("NULL")); - } + assertThat(value.toString(), is("NULL")); + } - @Test - public void evaluate_null_4() throws Exception { - Binding binding = Binding.valueOf("@{e.a.b}", null, null); + @Test + public void evaluate_null_4() throws Exception { + Binding binding = Binding.valueOf("@{e.a.b}", null, null); - Value value = binding.evaluate(null, data(), 0); + Value value = binding.evaluate(null, data(), 0); - assertThat(value.toString(), is("NULL")); - } + assertThat(value.toString(), is("NULL")); + } - @Test - public void evaluate_null_5() throws Exception { - Binding binding = Binding.valueOf("@{f.a.b}", null, null); + @Test + public void evaluate_null_5() throws Exception { + Binding binding = Binding.valueOf("@{f.a.b}", null, null); - Value value = binding.evaluate(null, data(), 0); + Value value = binding.evaluate(null, data(), 0); - assertThat(value.toString(), is("NULL")); - } + assertThat(value.toString(), is("NULL")); + } - @Test - public void evaluate_index() throws Exception { - Binding binding = Binding.valueOf("@{$index}", null, null); + @Test + public void evaluate_index() throws Exception { + Binding binding = Binding.valueOf("@{$index}", null, null); - Value value = binding.evaluate(null, data(), 0); + Value value = binding.evaluate(null, data(), 0); - assertThat(value.toString(), is("0")); - } + assertThat(value.toString(), is("0")); + } - @Test - public void evaluate_array_index() throws Exception { - Binding binding = Binding.valueOf("@{e[$index]}", null, null); + @Test + public void evaluate_array_index() throws Exception { + Binding binding = Binding.valueOf("@{e[$index]}", null, null); - Value value = binding.evaluate(null, data(), 1); + Value value = binding.evaluate(null, data(), 1); - assertThat(value.toString(), is("2")); - } + assertThat(value.toString(), is("2")); + } - @Test - public void evaluate_array_invalid_index_1() throws Exception { - Binding binding = Binding.valueOf("@{e[8]}", null, null); + @Test + public void evaluate_array_invalid_index_1() throws Exception { + Binding binding = Binding.valueOf("@{e[8]}", null, null); - Value value = binding.evaluate(null, data(), 1); + Value value = binding.evaluate(null, data(), 1); - assertThat(value.toString(), is("NULL")); - } + assertThat(value.toString(), is("NULL")); + } - @Test - public void evaluate_array_invalid_index_2() throws Exception { - Binding binding = Binding.valueOf("@{e[$index]}", null, null); + @Test + public void evaluate_array_invalid_index_2() throws Exception { + Binding binding = Binding.valueOf("@{e[$index]}", null, null); - Value value = binding.evaluate(null, data(), 8); + Value value = binding.evaluate(null, data(), 8); - assertThat(value.toString(), is("NULL")); - } + assertThat(value.toString(), is("NULL")); + } - @Test - public void evaluate_array_length() throws Exception { - Binding binding = Binding.valueOf("@{e[$length]}", null, null); + @Test + public void evaluate_array_length() throws Exception { + Binding binding = Binding.valueOf("@{e[$length]}", null, null); - Value value = binding.evaluate(null, data(), 1); + Value value = binding.evaluate(null, data(), 1); - assertThat(value.toString(), is("3")); - } + assertThat(value.toString(), is("3")); + } - @Test - public void evaluate_array_last_1() throws Exception { - Binding binding = Binding.valueOf("@{e[$last]}", null, null); + @Test + public void evaluate_array_last_1() throws Exception { + Binding binding = Binding.valueOf("@{e[$last]}", null, null); - Value value = binding.evaluate(null, data(), 1); + Value value = binding.evaluate(null, data(), 1); - assertThat(value.toString(), is("false")); - } + assertThat(value.toString(), is("false")); + } - @Test - public void evaluate_array_last_2() throws Exception { - Binding binding = Binding.valueOf("@{g[$last]}", null, null); + @Test + public void evaluate_array_last_2() throws Exception { + Binding binding = Binding.valueOf("@{g[$last]}", null, null); - Value value = binding.evaluate(null, data(), 1); + Value value = binding.evaluate(null, data(), 1); - assertThat(value.toString(), is("NULL")); - } + assertThat(value.toString(), is("NULL")); + } - @Test - public void assign_value_binding_1() throws Exception { - Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b.c"); - ObjectValue data = data(); - Value value = new Primitive(1); + @Test + public void assign_value_binding_1() throws Exception { + Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b.c"); + ObjectValue data = data(); + Value value = new Primitive(1); - binding.assign(value, data, 0); + binding.assign(value, data, 0); - value = binding.evaluate(null, data, 0); + value = binding.evaluate(null, data, 0); - assertThat(value.getAsString(), is("1")); + assertThat(value.getAsString(), is("1")); - } + } - @Test - public void assign_value_binding_2() throws Exception { - Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b.c.d"); - ObjectValue data = data(); - Value value = new Primitive(1); + @Test + public void assign_value_binding_2() throws Exception { + Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b.c.d"); + ObjectValue data = data(); + Value value = new Primitive(1); - binding.assign(value, data, 0); + binding.assign(value, data, 0); - value = binding.evaluate(null, data, 0); + value = binding.evaluate(null, data, 0); - assertThat(value.getAsString(), is("1")); + assertThat(value.getAsString(), is("1")); - } + } - @Test - public void assign_value_binding_3() throws Exception { - Binding.DataBinding binding = Binding.DataBinding.valueOf("a.x.y"); - ObjectValue data = data(); - Value value = new Primitive(1); + @Test + public void assign_value_binding_3() throws Exception { + Binding.DataBinding binding = Binding.DataBinding.valueOf("a.x.y"); + ObjectValue data = data(); + Value value = new Primitive(1); - binding.assign(value, data, 0); + binding.assign(value, data, 0); - value = binding.evaluate(null, data, 0); + value = binding.evaluate(null, data, 0); - assertThat(value.getAsString(), is("1")); + assertThat(value.getAsString(), is("1")); - } + } - @Test - public void assign_value_binding_4() throws Exception { - Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b[0]"); - ObjectValue data = data(); - Value value = new Primitive(1); + @Test + public void assign_value_binding_4() throws Exception { + Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b[0]"); + ObjectValue data = data(); + Value value = new Primitive(1); - binding.assign(value, data, 0); + binding.assign(value, data, 0); - value = binding.evaluate(null, data, 0); + value = binding.evaluate(null, data, 0); - assertThat(value.getAsString(), is("1")); + assertThat(value.getAsString(), is("1")); - } + } - @Test - public void assign_value_binding_5() throws Exception { - Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b[3]"); - ObjectValue data = data(); - Value value = new Primitive(1); + @Test + public void assign_value_binding_5() throws Exception { + Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b[3]"); + ObjectValue data = data(); + Value value = new Primitive(1); - binding.assign(value, data, 0); + binding.assign(value, data, 0); - value = binding.evaluate(null, data, 0); + value = binding.evaluate(null, data, 0); - assertThat(value.getAsString(), is("1")); + assertThat(value.getAsString(), is("1")); - } + } - @Test - public void assign_value_binding_6() throws Exception { - Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b[0].value"); - ObjectValue data = data(); - Value value = new Primitive(1); + @Test + public void assign_value_binding_6() throws Exception { + Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b[0].value"); + ObjectValue data = data(); + Value value = new Primitive(1); - binding.assign(value, data, 0); + binding.assign(value, data, 0); - value = binding.evaluate(null, data, 0); + value = binding.evaluate(null, data, 0); - assertThat(value.getAsString(), is("1")); + assertThat(value.getAsString(), is("1")); - } + } - @Test - public void assign_value_binding_7() throws Exception { - Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b[5].value"); - ObjectValue data = data(); - Value value = new Primitive(1); + @Test + public void assign_value_binding_7() throws Exception { + Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b[5].value"); + ObjectValue data = data(); + Value value = new Primitive(1); - binding.assign(value, data, 0); + binding.assign(value, data, 0); - value = binding.evaluate(null, data, 0); + value = binding.evaluate(null, data, 0); - assertThat(value.getAsString(), is("1")); + assertThat(value.getAsString(), is("1")); - } + } - @Test - public void assign_value_binding_8() throws Exception { - Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b[0]"); - ObjectValue data = data(); - ObjectValue value = new ObjectValue(); - value.add("x", new Primitive(true)); - value.add("y", new Primitive(10)); + @Test + public void assign_value_binding_8() throws Exception { + Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b[0]"); + ObjectValue data = data(); + ObjectValue value = new ObjectValue(); + value.add("x", new Primitive(true)); + value.add("y", new Primitive(10)); - binding.assign(value, data, 0); + binding.assign(value, data, 0); - Value result = Binding.DataBinding.valueOf("a.b[0].x").evaluate(null, data, 0); + Value result = Binding.DataBinding.valueOf("a.b[0].x").evaluate(null, data, 0); - assertThat(result.getAsString(), is("true")); + assertThat(result.getAsString(), is("true")); - } + } - @Test - public void assign_value_binding_9() throws Exception { - Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b[0].value"); - ObjectValue data = data(); - ObjectValue value = new ObjectValue(); - value.add("x", new Primitive(true)); - value.add("y", new Primitive(10)); + @Test + public void assign_value_binding_9() throws Exception { + Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b[0].value"); + ObjectValue data = data(); + ObjectValue value = new ObjectValue(); + value.add("x", new Primitive(true)); + value.add("y", new Primitive(10)); - binding.assign(value, data, 0); + binding.assign(value, data, 0); - Value result = Binding.DataBinding.valueOf("a.b[0].value.x").evaluate(null, data, 0); + Value result = Binding.DataBinding.valueOf("a.b[0].value.x").evaluate(null, data, 0); - assertThat(result.getAsString(), is("true")); + assertThat(result.getAsString(), is("true")); - } + } - @Test - public void assign_value_binding_10() throws Exception { - Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b[0][1]"); - ObjectValue data = data(); - Value value = new Primitive(true); + @Test + public void assign_value_binding_10() throws Exception { + Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b[0][1]"); + ObjectValue data = data(); + Value value = new Primitive(true); - binding.assign(value, data, 0); + binding.assign(value, data, 0); - Value result = Binding.DataBinding.valueOf("a.b[0][1]").evaluate(null, data, 0); + Value result = Binding.DataBinding.valueOf("a.b[0][1]").evaluate(null, data, 0); - assertThat(result.getAsString(), is("true")); + assertThat(result.getAsString(), is("true")); - } + } - @Test - public void assign_value_binding_11() throws Exception { - Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b[0][3].value"); - ObjectValue data = data(); - ObjectValue value = new ObjectValue(); - value.add("x", new Primitive(true)); - value.add("y", new Primitive(10)); + @Test + public void assign_value_binding_11() throws Exception { + Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b[0][3].value"); + ObjectValue data = data(); + ObjectValue value = new ObjectValue(); + value.add("x", new Primitive(true)); + value.add("y", new Primitive(10)); - binding.assign(value, data, 0); + binding.assign(value, data, 0); - Value result = Binding.DataBinding.valueOf("a.b[0][3].value.y").evaluate(null, data, 0); + Value result = Binding.DataBinding.valueOf("a.b[0][3].value.y").evaluate(null, data, 0); - assertThat(result.getAsString(), is("10")); + assertThat(result.getAsString(), is("10")); - } + } - @Test - public void assign_value_binding_12() throws Exception { - Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b.f"); - ObjectValue data = data(); - ObjectValue value = new ObjectValue(); - value.add("x", new Primitive(true)); - value.add("y", new Primitive(10)); + @Test + public void assign_value_binding_12() throws Exception { + Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b.f"); + ObjectValue data = data(); + ObjectValue value = new ObjectValue(); + value.add("x", new Primitive(true)); + value.add("y", new Primitive(10)); - binding.assign(value, data, 0); + binding.assign(value, data, 0); - Value result = Binding.DataBinding.valueOf("a.b.f.y").evaluate(null, data, 0); + Value result = Binding.DataBinding.valueOf("a.b.f.y").evaluate(null, data, 0); - assertThat(result.getAsString(), is("10")); + assertThat(result.getAsString(), is("10")); - result = Binding.DataBinding.valueOf("a.b.c").evaluate(null, data, 0); + result = Binding.DataBinding.valueOf("a.b.c").evaluate(null, data, 0); - assertThat(result.getAsString(), is("10")); - } + assertThat(result.getAsString(), is("10")); + } - @Test - public void assign_value_binding_13() throws Exception { - Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b[x]"); - ObjectValue data = data(); - Value value = new Primitive(1); + @Test + public void assign_value_binding_13() throws Exception { + Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b[x]"); + ObjectValue data = data(); + Value value = new Primitive(1); - binding.assign(value, data, 0); + binding.assign(value, data, 0); - value = binding.evaluate(null, data, 0); + value = binding.evaluate(null, data, 0); - assertThat(value.toString(), is("NULL")); + assertThat(value.toString(), is("NULL")); - } + } - @Test - public void assign_value_binding_14() throws Exception { - Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b[x].y"); - ObjectValue data = data(); - Value value = new Primitive(1); + @Test + public void assign_value_binding_14() throws Exception { + Binding.DataBinding binding = Binding.DataBinding.valueOf("a.b[x].y"); + ObjectValue data = data(); + Value value = new Primitive(1); - binding.assign(value, data, 0); + binding.assign(value, data, 0); - value = binding.evaluate(null, data, 0); + value = binding.evaluate(null, data, 0); - assertThat(value.toString(), is("NULL")); + assertThat(value.toString(), is("NULL")); - } + } } \ No newline at end of file diff --git a/proteus-core/src/test/java/com/flipkart/android/proteus/value/DimensionTest.java b/proteus-core/src/test/java/com/flipkart/android/proteus/value/DimensionTest.java index d1051f3d..9088e3c7 100644 --- a/proteus-core/src/test/java/com/flipkart/android/proteus/value/DimensionTest.java +++ b/proteus-core/src/test/java/com/flipkart/android/proteus/value/DimensionTest.java @@ -35,155 +35,155 @@ */ public class DimensionTest { - private static Context context() { - DisplayMetrics metric = new DisplayMetrics(); - Context context = mock(Context.class); - Resources resources = mock(Resources.class); - when(context.getResources()).thenReturn(resources); - when(resources.getDisplayMetrics()).thenReturn(metric); - return context; - } - - @Test - public void valueOf_Null() throws Exception { - Dimension d = Dimension.valueOf(null); - assertThat(d.value, is(0d)); - assertThat(d.unit, is(Dimension.DIMENSION_UNIT_PX)); - } - - @Test - public void valueOf_MatchParent() throws Exception { - Dimension d = Dimension.valueOf("match_parent"); - assertThat((int) d.value, is(ViewGroup.LayoutParams.MATCH_PARENT)); - assertThat(d.unit, is(Dimension.DIMENSION_UNIT_ENUM)); - } - - @Test - public void valueOf_WrapContent() throws Exception { - Dimension d; - d = Dimension.valueOf("wrap_content"); - assertThat((int) d.value, is(ViewGroup.LayoutParams.WRAP_CONTENT)); - assertThat(d.unit, is(Dimension.DIMENSION_UNIT_ENUM)); - } - - @Test - public void valueOf_Unit_Invalid() throws Exception { - Dimension d = Dimension.valueOf("abcd"); - assertThat(d.value, is(0d)); - assertThat(d.unit, is(Dimension.DIMENSION_UNIT_PX)); - - d = Dimension.valueOf("16q"); - assertThat(d.value, is(0d)); - assertThat(d.unit, is(Dimension.DIMENSION_UNIT_PX)); - - d = Dimension.valueOf("16"); - assertThat(d.value, is(0d)); - assertThat(d.unit, is(Dimension.DIMENSION_UNIT_PX)); - - d = Dimension.valueOf("1"); - assertThat(d.value, is(0d)); - assertThat(d.unit, is(Dimension.DIMENSION_UNIT_PX)); - } - - @Test - public void valueOf_Unit_None() throws Exception { - Dimension d = Dimension.valueOf("16"); - assertThat(d.value, is(0d)); - assertThat(d.unit, is(Dimension.DIMENSION_UNIT_PX)); - } - - @Test - public void valueOf_Unit_PX() throws Exception { - Dimension d = Dimension.valueOf("16px"); - assertThat(d.value, is(16d)); - assertThat(d.unit, is(Dimension.DIMENSION_UNIT_PX)); - } - - @Test - public void valueOf_Unit_DP() throws Exception { - Dimension d = Dimension.valueOf("16dp"); - assertThat(d.value, is(16d)); - assertThat(d.unit, is(Dimension.DIMENSION_UNIT_DP)); - } - - @Test - public void valueOf_Unit_SP() throws Exception { - Dimension d = Dimension.valueOf("16sp"); - assertThat(d.value, is(16d)); - assertThat(d.unit, is(Dimension.DIMENSION_UNIT_SP)); - } - - @Test - public void valueOf_Unit_PT() throws Exception { - Dimension d = Dimension.valueOf("16pt"); - assertThat(d.value, is(16d)); - assertThat(d.unit, is(Dimension.DIMENSION_UNIT_PT)); - } - - @Test - public void valueOf_Unit_IN() throws Exception { - Dimension d = Dimension.valueOf("16in"); - assertThat(d.value, is(16d)); - assertThat(d.unit, is(Dimension.DIMENSION_UNIT_IN)); - } - - @Test - public void valueOf_Unit_MM() throws Exception { - Dimension d = Dimension.valueOf("16mm"); - assertThat(d.value, is(16d)); - assertThat(d.unit, is(Dimension.DIMENSION_UNIT_MM)); - } - - @Test - public void valueOf_Unit_Negative() throws Exception { - Dimension d = Dimension.valueOf("-16dp"); - assertThat(d.value, is(-16d)); - assertThat(d.unit, is(Dimension.DIMENSION_UNIT_DP)); - } - - @Test - public void copy() throws Exception { - Dimension d = Dimension.valueOf("24dp"); - assertThat(d, is(d.copy())); - } - - @Test - public void cache() throws Exception { - Dimension d1 = Dimension.valueOf("16dp"); - Dimension d2 = Dimension.valueOf("16dp"); - - assertThat(d1, is(d2)); - } - - @Test - public void to_string() throws Exception { - String string = "16dp"; - Dimension dimension = Dimension.valueOf(string); - - assertThat(dimension.toString(), is(string)); - - string = "16.5dp"; - dimension = Dimension.valueOf(string); - - assertThat(dimension.toString(), is(string)); - - string = "match_parent"; - dimension = Dimension.valueOf(string); - - assertThat(dimension.toString(), is(string)); - } - - @Test - public void apply() throws Exception { - Dimension dimension = Dimension.valueOf("24dp"); - float result = dimension.apply(context()); - assertThat(result, is(24f)); - - dimension = Dimension.valueOf("match_parent"); - result = dimension.apply(context()); - assertThat(result, is(-1f)); - - result = Dimension.apply("24dp", context()); - assertThat(result, is(24f)); - } + private static Context context() { + DisplayMetrics metric = new DisplayMetrics(); + Context context = mock(Context.class); + Resources resources = mock(Resources.class); + when(context.getResources()).thenReturn(resources); + when(resources.getDisplayMetrics()).thenReturn(metric); + return context; + } + + @Test + public void valueOf_Null() throws Exception { + Dimension d = Dimension.valueOf(null); + assertThat(d.value, is(0d)); + assertThat(d.unit, is(Dimension.DIMENSION_UNIT_PX)); + } + + @Test + public void valueOf_MatchParent() throws Exception { + Dimension d = Dimension.valueOf("match_parent"); + assertThat((int) d.value, is(ViewGroup.LayoutParams.MATCH_PARENT)); + assertThat(d.unit, is(Dimension.DIMENSION_UNIT_ENUM)); + } + + @Test + public void valueOf_WrapContent() throws Exception { + Dimension d; + d = Dimension.valueOf("wrap_content"); + assertThat((int) d.value, is(ViewGroup.LayoutParams.WRAP_CONTENT)); + assertThat(d.unit, is(Dimension.DIMENSION_UNIT_ENUM)); + } + + @Test + public void valueOf_Unit_Invalid() throws Exception { + Dimension d = Dimension.valueOf("abcd"); + assertThat(d.value, is(0d)); + assertThat(d.unit, is(Dimension.DIMENSION_UNIT_PX)); + + d = Dimension.valueOf("16q"); + assertThat(d.value, is(0d)); + assertThat(d.unit, is(Dimension.DIMENSION_UNIT_PX)); + + d = Dimension.valueOf("16"); + assertThat(d.value, is(0d)); + assertThat(d.unit, is(Dimension.DIMENSION_UNIT_PX)); + + d = Dimension.valueOf("1"); + assertThat(d.value, is(0d)); + assertThat(d.unit, is(Dimension.DIMENSION_UNIT_PX)); + } + + @Test + public void valueOf_Unit_None() throws Exception { + Dimension d = Dimension.valueOf("16"); + assertThat(d.value, is(0d)); + assertThat(d.unit, is(Dimension.DIMENSION_UNIT_PX)); + } + + @Test + public void valueOf_Unit_PX() throws Exception { + Dimension d = Dimension.valueOf("16px"); + assertThat(d.value, is(16d)); + assertThat(d.unit, is(Dimension.DIMENSION_UNIT_PX)); + } + + @Test + public void valueOf_Unit_DP() throws Exception { + Dimension d = Dimension.valueOf("16dp"); + assertThat(d.value, is(16d)); + assertThat(d.unit, is(Dimension.DIMENSION_UNIT_DP)); + } + + @Test + public void valueOf_Unit_SP() throws Exception { + Dimension d = Dimension.valueOf("16sp"); + assertThat(d.value, is(16d)); + assertThat(d.unit, is(Dimension.DIMENSION_UNIT_SP)); + } + + @Test + public void valueOf_Unit_PT() throws Exception { + Dimension d = Dimension.valueOf("16pt"); + assertThat(d.value, is(16d)); + assertThat(d.unit, is(Dimension.DIMENSION_UNIT_PT)); + } + + @Test + public void valueOf_Unit_IN() throws Exception { + Dimension d = Dimension.valueOf("16in"); + assertThat(d.value, is(16d)); + assertThat(d.unit, is(Dimension.DIMENSION_UNIT_IN)); + } + + @Test + public void valueOf_Unit_MM() throws Exception { + Dimension d = Dimension.valueOf("16mm"); + assertThat(d.value, is(16d)); + assertThat(d.unit, is(Dimension.DIMENSION_UNIT_MM)); + } + + @Test + public void valueOf_Unit_Negative() throws Exception { + Dimension d = Dimension.valueOf("-16dp"); + assertThat(d.value, is(-16d)); + assertThat(d.unit, is(Dimension.DIMENSION_UNIT_DP)); + } + + @Test + public void copy() throws Exception { + Dimension d = Dimension.valueOf("24dp"); + assertThat(d, is(d.copy())); + } + + @Test + public void cache() throws Exception { + Dimension d1 = Dimension.valueOf("16dp"); + Dimension d2 = Dimension.valueOf("16dp"); + + assertThat(d1, is(d2)); + } + + @Test + public void to_string() throws Exception { + String string = "16dp"; + Dimension dimension = Dimension.valueOf(string); + + assertThat(dimension.toString(), is(string)); + + string = "16.5dp"; + dimension = Dimension.valueOf(string); + + assertThat(dimension.toString(), is(string)); + + string = "match_parent"; + dimension = Dimension.valueOf(string); + + assertThat(dimension.toString(), is(string)); + } + + @Test + public void apply() throws Exception { + Dimension dimension = Dimension.valueOf("24dp"); + float result = dimension.apply(context()); + assertThat(result, is(24f)); + + dimension = Dimension.valueOf("match_parent"); + result = dimension.apply(context()); + assertThat(result, is(-1f)); + + result = Dimension.apply("24dp", context()); + assertThat(result, is(24f)); + } } \ No newline at end of file From 9ed5656c40c72fa8e97234e48a51d5a28270f0ad Mon Sep 17 00:00:00 2001 From: Aditya Sharat Date: Sun, 13 Jan 2019 00:48:00 +0000 Subject: [PATCH 18/19] reformat code --- .../support/v7/RecyclerViewModule.java | 250 +++++++++--------- .../adapter/ProteusRecyclerViewAdapter.java | 8 +- .../support/v7/adapter/ProteusViewHolder.java | 18 +- .../adapter/RecyclerViewAdapterFactory.java | 22 +- .../support/v7/adapter/SimpleListAdapter.java | 78 +++--- .../layoutmanager/LayoutManagerBuilder.java | 4 +- .../layoutmanager/LayoutManagerFactory.java | 22 +- .../ProteusLinearLayoutManager.java | 28 +- .../v7/widget/ProteusRecyclerView.java | 42 +-- .../support/v7/widget/RecyclerViewParser.java | 210 +++++++-------- 10 files changed, 341 insertions(+), 341 deletions(-) diff --git a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/RecyclerViewModule.java b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/RecyclerViewModule.java index f12480ab..865db287 100644 --- a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/RecyclerViewModule.java +++ b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/RecyclerViewModule.java @@ -39,154 +39,154 @@ */ public class RecyclerViewModule implements ProteusBuilder.Module { - static final String ADAPTER_SIMPLE_LIST = "SimpleListAdapter"; - - static final String LAYOUT_MANAGER_LINEAR = "LinearLayoutManager"; + static final String ADAPTER_SIMPLE_LIST = "SimpleListAdapter"; + + static final String LAYOUT_MANAGER_LINEAR = "LinearLayoutManager"; + + @NonNull + private final RecyclerViewAdapterFactory adapterFactory; + + @NonNull + private final LayoutManagerFactory layoutManagerFactory; + + /** + *

+ * Returns a new instance of the Recycler View Module. + *

+ * + * @param adapterFactory The adapter factory to be used to evaluate the {@link RecyclerViewParser#ATTRIBUTE_ADAPTER} attribute. + * @param layoutManagerFactory The layout manager factory to evaluate the {@link RecyclerViewParser#ATTRIBUTE_LAYOUT_MANAGER} attribute. + */ + RecyclerViewModule(@NonNull RecyclerViewAdapterFactory adapterFactory, @NonNull LayoutManagerFactory layoutManagerFactory) { + this.adapterFactory = adapterFactory; + this.layoutManagerFactory = layoutManagerFactory; + } + + /** + *

+ * The default constructor method to create a new instance of this class. This method internally + * uses the {@link Builder} and registers the default Adapters and Layout Managers of the + * Recycler View. + *

+ * + * @return Returns a new instance of the module with default implementations registered. + * @see SimpleListAdapter + * @see ProteusLinearLayoutManager + */ + public static RecyclerViewModule create() { + return new Builder().build(); + } + + @Override + public void registerWith(ProteusBuilder builder) { + builder.register(new RecyclerViewParser(adapterFactory, layoutManagerFactory)); + } + + /** + * Use the Recycler View Module Builder to register custom {@link ProteusRecyclerViewAdapter} + * implementations. A default {@link ProteusRecyclerViewAdapter} and + * {@link android.support.v7.widget.RecyclerView.LayoutManager} are included by default. To + * exclude them call {@link #excludeDefaultAdapters()} and {@link #excludeDefaultLayoutManagers()}. + * + * @author adityasharat + * @see ProteusRecyclerViewAdapter + * @see RecyclerViewAdapterFactory + * @see SimpleListAdapter + * @see LayoutManagerFactory + * @see ProteusLinearLayoutManager + */ + @SuppressWarnings("WeakerAccess") + public static class Builder { @NonNull - private final RecyclerViewAdapterFactory adapterFactory; + private final RecyclerViewAdapterFactory adapterFactory = new RecyclerViewAdapterFactory(); @NonNull - private final LayoutManagerFactory layoutManagerFactory; + private LayoutManagerFactory layoutManagerFactory = new LayoutManagerFactory(); + + private boolean includeDefaultAdapters = true; + + private boolean includeDefaultLayoutManagers = true; + + /** + *

+ * Registers a new {@link ProteusRecyclerViewAdapter}. + *

+ * + * @param type The 'type' of the adapter which will be used in the {@link RecyclerViewParser#ATTRIBUTE_ADAPTER} attribute. + * @param builder The builder for the adapter. + * @return this builder. + */ + public Builder register(@NonNull String type, @NonNull ProteusRecyclerViewAdapter.Builder builder) { + adapterFactory.register(type, builder); + return this; + } /** *

- * Returns a new instance of the Recycler View Module. + * Registers a new {@link ProteusRecyclerViewAdapter}. *

* - * @param adapterFactory The adapter factory to be used to evaluate the {@link RecyclerViewParser#ATTRIBUTE_ADAPTER} attribute. - * @param layoutManagerFactory The layout manager factory to evaluate the {@link RecyclerViewParser#ATTRIBUTE_LAYOUT_MANAGER} attribute. + * @param type The {@link RecyclerViewParser#ATTRIBUTE_TYPE} of the layout manager which will be used in the {@link RecyclerViewParser#ATTRIBUTE_LAYOUT_MANAGER} attribute. + * @param builder The builder for the layout manager. + * @return this builder. */ - RecyclerViewModule(@NonNull RecyclerViewAdapterFactory adapterFactory, @NonNull LayoutManagerFactory layoutManagerFactory) { - this.adapterFactory = adapterFactory; - this.layoutManagerFactory = layoutManagerFactory; + public Builder register(@NonNull String type, @NonNull LayoutManagerBuilder builder) { + layoutManagerFactory.register(type, builder); + return this; } /** *

- * The default constructor method to create a new instance of this class. This method internally - * uses the {@link Builder} and registers the default Adapters and Layout Managers of the - * Recycler View. + * Will exclude the default {@link ProteusRecyclerViewAdapter} implementations from the module. *

* - * @return Returns a new instance of the module with default implementations registered. - * @see SimpleListAdapter - * @see ProteusLinearLayoutManager + * @return this builder. */ - public static RecyclerViewModule create() { - return new Builder().build(); + public Builder excludeDefaultAdapters() { + includeDefaultAdapters = false; + return this; } - @Override - public void registerWith(ProteusBuilder builder) { - builder.register(new RecyclerViewParser(adapterFactory, layoutManagerFactory)); + /** + *

+ * Will exclude the default {@link android.support.v7.widget.RecyclerView.LayoutManager} + * implementations from the module. + *

+ * + * @return this builder. + */ + public Builder excludeDefaultLayoutManagers() { + includeDefaultLayoutManagers = false; + return this; } /** - * Use the Recycler View Module Builder to register custom {@link ProteusRecyclerViewAdapter} - * implementations. A default {@link ProteusRecyclerViewAdapter} and - * {@link android.support.v7.widget.RecyclerView.LayoutManager} are included by default. To - * exclude them call {@link #excludeDefaultAdapters()} and {@link #excludeDefaultLayoutManagers()}. + *

+ * Returns a new instance of {@link RecyclerViewModule}. + *

* - * @author adityasharat - * @see ProteusRecyclerViewAdapter - * @see RecyclerViewAdapterFactory - * @see SimpleListAdapter - * @see LayoutManagerFactory - * @see ProteusLinearLayoutManager + * @return a new instance of {@link RecyclerViewModule}. */ - @SuppressWarnings("WeakerAccess") - public static class Builder { - - @NonNull - private final RecyclerViewAdapterFactory adapterFactory = new RecyclerViewAdapterFactory(); - - @NonNull - private LayoutManagerFactory layoutManagerFactory = new LayoutManagerFactory(); - - private boolean includeDefaultAdapters = true; - - private boolean includeDefaultLayoutManagers = true; - - /** - *

- * Registers a new {@link ProteusRecyclerViewAdapter}. - *

- * - * @param type The 'type' of the adapter which will be used in the {@link RecyclerViewParser#ATTRIBUTE_ADAPTER} attribute. - * @param builder The builder for the adapter. - * @return this builder. - */ - public Builder register(@NonNull String type, @NonNull ProteusRecyclerViewAdapter.Builder builder) { - adapterFactory.register(type, builder); - return this; - } - - /** - *

- * Registers a new {@link ProteusRecyclerViewAdapter}. - *

- * - * @param type The {@link RecyclerViewParser#ATTRIBUTE_TYPE} of the layout manager which will be used in the {@link RecyclerViewParser#ATTRIBUTE_LAYOUT_MANAGER} attribute. - * @param builder The builder for the layout manager. - * @return this builder. - */ - public Builder register(@NonNull String type, @NonNull LayoutManagerBuilder builder) { - layoutManagerFactory.register(type, builder); - return this; - } - - /** - *

- * Will exclude the default {@link ProteusRecyclerViewAdapter} implementations from the module. - *

- * - * @return this builder. - */ - public Builder excludeDefaultAdapters() { - includeDefaultAdapters = false; - return this; - } - - /** - *

- * Will exclude the default {@link android.support.v7.widget.RecyclerView.LayoutManager} - * implementations from the module. - *

- * - * @return this builder. - */ - public Builder excludeDefaultLayoutManagers() { - includeDefaultLayoutManagers = false; - return this; - } - - /** - *

- * Returns a new instance of {@link RecyclerViewModule}. - *

- * - * @return a new instance of {@link RecyclerViewModule}. - */ - public RecyclerViewModule build() { - - if (includeDefaultAdapters) { - registerDefaultAdapters(); - } - - if (includeDefaultLayoutManagers) { - registerDefaultLayoutManagers(); - } - - return new RecyclerViewModule(adapterFactory, layoutManagerFactory); - } - - private void registerDefaultAdapters() { - register(ADAPTER_SIMPLE_LIST, SimpleListAdapter.BUILDER); - } - - private void registerDefaultLayoutManagers() { - register(LAYOUT_MANAGER_LINEAR, ProteusLinearLayoutManager.BUILDER); - } + public RecyclerViewModule build() { + + if (includeDefaultAdapters) { + registerDefaultAdapters(); + } + + if (includeDefaultLayoutManagers) { + registerDefaultLayoutManagers(); + } + + return new RecyclerViewModule(adapterFactory, layoutManagerFactory); + } + + private void registerDefaultAdapters() { + register(ADAPTER_SIMPLE_LIST, SimpleListAdapter.BUILDER); + } + + private void registerDefaultLayoutManagers() { + register(LAYOUT_MANAGER_LINEAR, ProteusLinearLayoutManager.BUILDER); } + } } diff --git a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/ProteusRecyclerViewAdapter.java b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/ProteusRecyclerViewAdapter.java index fb402f24..e3064047 100644 --- a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/ProteusRecyclerViewAdapter.java +++ b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/ProteusRecyclerViewAdapter.java @@ -30,9 +30,9 @@ public abstract class ProteusRecyclerViewAdapter extends RecyclerView.Adapter { - public interface Builder { - @NonNull - A create(@NonNull ProteusRecyclerView view, @NonNull ObjectValue config); - } + public interface Builder { + @NonNull + A create(@NonNull ProteusRecyclerView view, @NonNull ObjectValue config); + } } diff --git a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/ProteusViewHolder.java b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/ProteusViewHolder.java index 61d4e11e..c1fc0bdd 100644 --- a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/ProteusViewHolder.java +++ b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/ProteusViewHolder.java @@ -29,15 +29,15 @@ */ class ProteusViewHolder extends RecyclerView.ViewHolder { - @NonNull - final ProteusContext context; + @NonNull + final ProteusContext context; - @NonNull - public final ProteusView view; + @NonNull + public final ProteusView view; - ProteusViewHolder(@NonNull ProteusView view) { - super(view.getAsView()); - this.view = view; - this.context = view.getViewManager().getContext(); - } + ProteusViewHolder(@NonNull ProteusView view) { + super(view.getAsView()); + this.view = view; + this.context = view.getViewManager().getContext(); + } } diff --git a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/RecyclerViewAdapterFactory.java b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/RecyclerViewAdapterFactory.java index 97d150fc..d00259d3 100644 --- a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/RecyclerViewAdapterFactory.java +++ b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/RecyclerViewAdapterFactory.java @@ -32,18 +32,18 @@ */ public class RecyclerViewAdapterFactory { - private Map adapters = new HashMap<>(); + private Map adapters = new HashMap<>(); - public void register(@NonNull String type, @NonNull ProteusRecyclerViewAdapter.Builder builder) { - adapters.put(type, builder); - } + public void register(@NonNull String type, @NonNull ProteusRecyclerViewAdapter.Builder builder) { + adapters.put(type, builder); + } - @Nullable - public ProteusRecyclerViewAdapter.Builder remove(@NonNull String type) { - return adapters.remove(type); - } + @Nullable + public ProteusRecyclerViewAdapter.Builder remove(@NonNull String type) { + return adapters.remove(type); + } - public ProteusRecyclerViewAdapter create(@NonNull String type, @NonNull ProteusRecyclerView view, @NonNull ObjectValue config) { - return adapters.get(type).create(view, config); - } + public ProteusRecyclerViewAdapter create(@NonNull String type, @NonNull ProteusRecyclerView view, @NonNull ObjectValue config) { + return adapters.get(type).create(view, config); + } } diff --git a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/SimpleListAdapter.java b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/SimpleListAdapter.java index 59de54d6..2da18af2 100644 --- a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/SimpleListAdapter.java +++ b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/adapter/SimpleListAdapter.java @@ -37,51 +37,51 @@ */ public class SimpleListAdapter extends ProteusRecyclerViewAdapter { - private static final String ATTRIBUTE_ITEM_LAYOUT = "item-layout"; - private static final String ATTRIBUTE_ITEM_COUNT = "item-count"; + private static final String ATTRIBUTE_ITEM_LAYOUT = "item-layout"; + private static final String ATTRIBUTE_ITEM_COUNT = "item-count"; - public static final Builder BUILDER = new Builder() { - @NonNull - @Override - public SimpleListAdapter create(@NonNull ProteusRecyclerView view, @NonNull ObjectValue config) { - Layout layout = config.getAsObject().getAsLayout(ATTRIBUTE_ITEM_LAYOUT); - Integer count = config.getAsObject().getAsInteger(ATTRIBUTE_ITEM_COUNT); - ObjectValue data = view.getViewManager().getDataContext().getData(); - ProteusContext context = (ProteusContext) view.getContext(); + public static final Builder BUILDER = new Builder() { + @NonNull + @Override + public SimpleListAdapter create(@NonNull ProteusRecyclerView view, @NonNull ObjectValue config) { + Layout layout = config.getAsObject().getAsLayout(ATTRIBUTE_ITEM_LAYOUT); + Integer count = config.getAsObject().getAsInteger(ATTRIBUTE_ITEM_COUNT); + ObjectValue data = view.getViewManager().getDataContext().getData(); + ProteusContext context = (ProteusContext) view.getContext(); - return new SimpleListAdapter(context.getInflater(), data, layout, count != null ? count : 0); - } - }; + return new SimpleListAdapter(context.getInflater(), data, layout, count != null ? count : 0); + } + }; - private ProteusLayoutInflater inflater; + private ProteusLayoutInflater inflater; - private ObjectValue data; - private int count; - private Layout layout; - private Map scope; + private ObjectValue data; + private int count; + private Layout layout; + private Map scope; - private SimpleListAdapter(ProteusLayoutInflater inflater, ObjectValue data, Layout layout, int count) { - this.inflater = inflater; - this.data = data; - this.count = count; - this.layout = new Layout(layout.type, layout.attributes, null, layout.extras); - this.scope = layout.data; - } + private SimpleListAdapter(ProteusLayoutInflater inflater, ObjectValue data, Layout layout, int count) { + this.inflater = inflater; + this.data = data; + this.count = count; + this.layout = new Layout(layout.type, layout.attributes, null, layout.extras); + this.scope = layout.data; + } - @Override - public ProteusViewHolder onCreateViewHolder(ViewGroup parent, int type) { - ProteusView view = inflater.inflate(layout, new ObjectValue()); - return new ProteusViewHolder(view); - } + @Override + public ProteusViewHolder onCreateViewHolder(ViewGroup parent, int type) { + ProteusView view = inflater.inflate(layout, new ObjectValue()); + return new ProteusViewHolder(view); + } - @Override - public void onBindViewHolder(ProteusViewHolder holder, int position) { - DataContext context = DataContext.create(holder.context, data, position, scope); - holder.view.getViewManager().update(context.getData()); - } + @Override + public void onBindViewHolder(ProteusViewHolder holder, int position) { + DataContext context = DataContext.create(holder.context, data, position, scope); + holder.view.getViewManager().update(context.getData()); + } - @Override - public int getItemCount() { - return count; - } + @Override + public int getItemCount() { + return count; + } } diff --git a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/layoutmanager/LayoutManagerBuilder.java b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/layoutmanager/LayoutManagerBuilder.java index 8e74cc11..c31617ae 100644 --- a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/layoutmanager/LayoutManagerBuilder.java +++ b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/layoutmanager/LayoutManagerBuilder.java @@ -29,7 +29,7 @@ */ public interface LayoutManagerBuilder { - @NonNull - LM create(@NonNull ProteusRecyclerView view, @NonNull ObjectValue config); + @NonNull + LM create(@NonNull ProteusRecyclerView view, @NonNull ObjectValue config); } diff --git a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/layoutmanager/LayoutManagerFactory.java b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/layoutmanager/LayoutManagerFactory.java index 3ceb8fda..8c9311ac 100644 --- a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/layoutmanager/LayoutManagerFactory.java +++ b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/layoutmanager/LayoutManagerFactory.java @@ -33,19 +33,19 @@ */ public class LayoutManagerFactory { - private Map builders = new HashMap<>(); + private Map builders = new HashMap<>(); - public void register(@NonNull String type, @NonNull LayoutManagerBuilder builder) { - builders.put(type, builder); - } + public void register(@NonNull String type, @NonNull LayoutManagerBuilder builder) { + builders.put(type, builder); + } - @Nullable - public LayoutManagerBuilder remove(@NonNull String type) { - return builders.remove(type); - } + @Nullable + public LayoutManagerBuilder remove(@NonNull String type) { + return builders.remove(type); + } - public RecyclerView.LayoutManager create(@NonNull String type, @NonNull ProteusRecyclerView view, @NonNull ObjectValue config) { - return builders.get(type).create(view, config); - } + public RecyclerView.LayoutManager create(@NonNull String type, @NonNull ProteusRecyclerView view, @NonNull ObjectValue config) { + return builders.get(type).create(view, config); + } } diff --git a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/layoutmanager/ProteusLinearLayoutManager.java b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/layoutmanager/ProteusLinearLayoutManager.java index d7bf86db..fb417b08 100644 --- a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/layoutmanager/ProteusLinearLayoutManager.java +++ b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/layoutmanager/ProteusLinearLayoutManager.java @@ -28,23 +28,23 @@ */ public class ProteusLinearLayoutManager extends LinearLayoutManager { - private static final String ATTRIBUTE_ORIENTATION = "orientation"; - private static final String ATTRIBUTE_REVERSE_LAYOUT = "reverse"; + private static final String ATTRIBUTE_ORIENTATION = "orientation"; + private static final String ATTRIBUTE_REVERSE_LAYOUT = "reverse"; - public static final LayoutManagerBuilder BUILDER = new LayoutManagerBuilder() { + public static final LayoutManagerBuilder BUILDER = new LayoutManagerBuilder() { - @NonNull - @Override - public ProteusLinearLayoutManager create(@NonNull ProteusRecyclerView view, @NonNull ObjectValue config) { + @NonNull + @Override + public ProteusLinearLayoutManager create(@NonNull ProteusRecyclerView view, @NonNull ObjectValue config) { - int orientation = config.getAsInteger(ATTRIBUTE_ORIENTATION, LinearLayoutManager.VERTICAL); - boolean reverseLayout = config.getAsBoolean(ATTRIBUTE_REVERSE_LAYOUT, false); + int orientation = config.getAsInteger(ATTRIBUTE_ORIENTATION, LinearLayoutManager.VERTICAL); + boolean reverseLayout = config.getAsBoolean(ATTRIBUTE_REVERSE_LAYOUT, false); - return new ProteusLinearLayoutManager(view.getContext(), orientation, reverseLayout); - } - }; - - public ProteusLinearLayoutManager(Context context, int orientation, boolean reverseLayout) { - super(context, orientation, reverseLayout); + return new ProteusLinearLayoutManager(view.getContext(), orientation, reverseLayout); } + }; + + public ProteusLinearLayoutManager(Context context, int orientation, boolean reverseLayout) { + super(context, orientation, reverseLayout); + } } diff --git a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/ProteusRecyclerView.java b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/ProteusRecyclerView.java index 6da72509..ec762189 100644 --- a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/ProteusRecyclerView.java +++ b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/ProteusRecyclerView.java @@ -31,25 +31,25 @@ public class ProteusRecyclerView extends RecyclerView implements ProteusView { - Manager manager; - - public ProteusRecyclerView(ProteusContext context) { - super(context); - } - - @Override - public Manager getViewManager() { - return manager; - } - - @Override - public void setViewManager(@NonNull Manager manager) { - this.manager = manager; - } - - @NonNull - @Override - public View getAsView() { - return this; - } + Manager manager; + + public ProteusRecyclerView(ProteusContext context) { + super(context); + } + + @Override + public Manager getViewManager() { + return manager; + } + + @Override + public void setViewManager(@NonNull Manager manager) { + this.manager = manager; + } + + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/RecyclerViewParser.java b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/RecyclerViewParser.java index c7c4c8b3..3d0da93c 100644 --- a/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/RecyclerViewParser.java +++ b/recyclerview-v7/src/main/java/com/flipkart/android/proteus/support/v7/widget/RecyclerViewParser.java @@ -46,109 +46,109 @@ public class RecyclerViewParser extends ViewTypeParser { - public static final String ATTRIBUTE_ADAPTER = "adapter"; - public static final String ATTRIBUTE_LAYOUT_MANAGER = "layout_manager"; - - public static final String ATTRIBUTE_TYPE = ProteusConstants.TYPE; - - @NonNull - private final RecyclerViewAdapterFactory adapterFactory; - - @NonNull - private final LayoutManagerFactory layoutManagerFactory; - - public RecyclerViewParser(@NonNull RecyclerViewAdapterFactory adapterFactory, @NonNull LayoutManagerFactory layoutManagerFactory) { - this.adapterFactory = adapterFactory; - this.layoutManagerFactory = layoutManagerFactory; - } - - @NonNull - @Override - public String getType() { - return "RecyclerView"; - } - - @Nullable - @Override - public String getParentType() { - return "ViewGroup"; - } - - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { - return new ProteusRecyclerView(context); - } - - @NonNull - @Override - public ProteusView.Manager createViewManager(@NonNull ProteusContext context, @NonNull ProteusView view, @NonNull Layout layout, - @NonNull ObjectValue data, @Nullable ViewTypeParser caller, @Nullable ViewGroup parent, - int dataIndex) { - DataContext dataContext = createDataContext(context, layout, data, parent, dataIndex); - return new AdapterBasedViewManager(context, null != caller ? caller : this, view.getAsView(), layout, dataContext); - } - - @Override - protected void addAttributeProcessors() { - - addAttributeProcessor(ATTRIBUTE_ADAPTER, new AttributeProcessor() { - - @Override - public void handleValue(V view, Value value) { - if (value.isObject()) { - String type = value.getAsObject().getAsString(ATTRIBUTE_TYPE); - if (type != null) { - ProteusRecyclerViewAdapter adapter = adapterFactory.create(type, (ProteusRecyclerView) view, value.getAsObject()); - view.setAdapter(adapter); - } - } - } - - @Override - public void handleResource(V view, Resource resource) { - throw new IllegalArgumentException("Recycler View 'adapter' expects only object values"); - } - - @Override - public void handleAttributeResource(V view, AttributeResource attribute) { - throw new IllegalArgumentException("Recycler View 'adapter' expects only object values"); - } - - @Override - public void handleStyleResource(V view, StyleResource style) { - throw new IllegalArgumentException("Recycler View 'adapter' expects only object values"); - } - }); - - addAttributeProcessor(ATTRIBUTE_LAYOUT_MANAGER, new AttributeProcessor() { - - @Override - public void handleValue(V view, Value value) { - if (value.isObject()) { - String type = value.getAsObject().getAsString(ATTRIBUTE_TYPE); - if (type != null) { - RecyclerView.LayoutManager layoutManager = layoutManagerFactory.create(type, (ProteusRecyclerView) view, value.getAsObject()); - view.setLayoutManager(layoutManager); - } - } - } - - @Override - public void handleResource(V view, Resource resource) { - throw new IllegalArgumentException("Recycler View 'layout_manager' expects only object values"); - } - - @Override - public void handleAttributeResource(V view, AttributeResource attribute) { - throw new IllegalArgumentException("Recycler View 'layout_manager' expects only object values"); - } - - @Override - public void handleStyleResource(V view, StyleResource style) { - throw new IllegalArgumentException("Recycler View 'layout_manager' expects only object values"); - } - }); - - } + public static final String ATTRIBUTE_ADAPTER = "adapter"; + public static final String ATTRIBUTE_LAYOUT_MANAGER = "layout_manager"; + + public static final String ATTRIBUTE_TYPE = ProteusConstants.TYPE; + + @NonNull + private final RecyclerViewAdapterFactory adapterFactory; + + @NonNull + private final LayoutManagerFactory layoutManagerFactory; + + public RecyclerViewParser(@NonNull RecyclerViewAdapterFactory adapterFactory, @NonNull LayoutManagerFactory layoutManagerFactory) { + this.adapterFactory = adapterFactory; + this.layoutManagerFactory = layoutManagerFactory; + } + + @NonNull + @Override + public String getType() { + return "RecyclerView"; + } + + @Nullable + @Override + public String getParentType() { + return "ViewGroup"; + } + + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { + return new ProteusRecyclerView(context); + } + + @NonNull + @Override + public ProteusView.Manager createViewManager(@NonNull ProteusContext context, @NonNull ProteusView view, @NonNull Layout layout, + @NonNull ObjectValue data, @Nullable ViewTypeParser caller, @Nullable ViewGroup parent, + int dataIndex) { + DataContext dataContext = createDataContext(context, layout, data, parent, dataIndex); + return new AdapterBasedViewManager(context, null != caller ? caller : this, view.getAsView(), layout, dataContext); + } + + @Override + protected void addAttributeProcessors() { + + addAttributeProcessor(ATTRIBUTE_ADAPTER, new AttributeProcessor() { + + @Override + public void handleValue(V view, Value value) { + if (value.isObject()) { + String type = value.getAsObject().getAsString(ATTRIBUTE_TYPE); + if (type != null) { + ProteusRecyclerViewAdapter adapter = adapterFactory.create(type, (ProteusRecyclerView) view, value.getAsObject()); + view.setAdapter(adapter); + } + } + } + + @Override + public void handleResource(V view, Resource resource) { + throw new IllegalArgumentException("Recycler View 'adapter' expects only object values"); + } + + @Override + public void handleAttributeResource(V view, AttributeResource attribute) { + throw new IllegalArgumentException("Recycler View 'adapter' expects only object values"); + } + + @Override + public void handleStyleResource(V view, StyleResource style) { + throw new IllegalArgumentException("Recycler View 'adapter' expects only object values"); + } + }); + + addAttributeProcessor(ATTRIBUTE_LAYOUT_MANAGER, new AttributeProcessor() { + + @Override + public void handleValue(V view, Value value) { + if (value.isObject()) { + String type = value.getAsObject().getAsString(ATTRIBUTE_TYPE); + if (type != null) { + RecyclerView.LayoutManager layoutManager = layoutManagerFactory.create(type, (ProteusRecyclerView) view, value.getAsObject()); + view.setLayoutManager(layoutManager); + } + } + } + + @Override + public void handleResource(V view, Resource resource) { + throw new IllegalArgumentException("Recycler View 'layout_manager' expects only object values"); + } + + @Override + public void handleAttributeResource(V view, AttributeResource attribute) { + throw new IllegalArgumentException("Recycler View 'layout_manager' expects only object values"); + } + + @Override + public void handleStyleResource(V view, StyleResource style) { + throw new IllegalArgumentException("Recycler View 'layout_manager' expects only object values"); + } + }); + + } } From da0a92f1b0e8f037cf97256e47a95772996db338 Mon Sep 17 00:00:00 2001 From: Aditya Sharat Date: Sun, 13 Jan 2019 00:48:09 +0000 Subject: [PATCH 19/19] reformat code --- .../proteus/support/v4/SupportV4Module.java | 18 +++---- .../support/v4/view/ProteusViewPager.java | 42 ++++++++-------- .../support/v4/view/ViewPagerParser.java | 48 +++++++++---------- 3 files changed, 54 insertions(+), 54 deletions(-) diff --git a/support-v4/src/main/java/com/flipkart/android/proteus/support/v4/SupportV4Module.java b/support-v4/src/main/java/com/flipkart/android/proteus/support/v4/SupportV4Module.java index c501c205..106438ab 100644 --- a/support-v4/src/main/java/com/flipkart/android/proteus/support/v4/SupportV4Module.java +++ b/support-v4/src/main/java/com/flipkart/android/proteus/support/v4/SupportV4Module.java @@ -27,15 +27,15 @@ public class SupportV4Module implements ProteusBuilder.Module { - private SupportV4Module() { - } + private SupportV4Module() { + } - public static SupportV4Module create() { - return new SupportV4Module(); - } + public static SupportV4Module create() { + return new SupportV4Module(); + } - @Override - public void registerWith(ProteusBuilder builder) { - builder.register(new ViewPagerParser()); - } + @Override + public void registerWith(ProteusBuilder builder) { + builder.register(new ViewPagerParser()); + } } diff --git a/support-v4/src/main/java/com/flipkart/android/proteus/support/v4/view/ProteusViewPager.java b/support-v4/src/main/java/com/flipkart/android/proteus/support/v4/view/ProteusViewPager.java index b98a0782..cd86ac68 100644 --- a/support-v4/src/main/java/com/flipkart/android/proteus/support/v4/view/ProteusViewPager.java +++ b/support-v4/src/main/java/com/flipkart/android/proteus/support/v4/view/ProteusViewPager.java @@ -30,25 +30,25 @@ public class ProteusViewPager extends android.support.v4.view.ViewPager implements ProteusView { - private Manager viewManager; - - public ProteusViewPager(ProteusContext context) { - super(context); - } - - @Override - public Manager getViewManager() { - return viewManager; - } - - @Override - public void setViewManager(@NonNull Manager manager) { - this.viewManager = manager; - } - - @NonNull - @Override - public View getAsView() { - return this; - } + private Manager viewManager; + + public ProteusViewPager(ProteusContext context) { + super(context); + } + + @Override + public Manager getViewManager() { + return viewManager; + } + + @Override + public void setViewManager(@NonNull Manager manager) { + this.viewManager = manager; + } + + @NonNull + @Override + public View getAsView() { + return this; + } } diff --git a/support-v4/src/main/java/com/flipkart/android/proteus/support/v4/view/ViewPagerParser.java b/support-v4/src/main/java/com/flipkart/android/proteus/support/v4/view/ViewPagerParser.java index 44c6a3e3..974496ae 100644 --- a/support-v4/src/main/java/com/flipkart/android/proteus/support/v4/view/ViewPagerParser.java +++ b/support-v4/src/main/java/com/flipkart/android/proteus/support/v4/view/ViewPagerParser.java @@ -37,33 +37,33 @@ public class ViewPagerParser extends ViewTypeParser { - @NonNull - @Override - public String getType() { - return "ViewPager"; - } + @NonNull + @Override + public String getType() { + return "ViewPager"; + } - @Nullable - @Override - public String getParentType() { - return "ViewGroup"; - } + @Nullable + @Override + public String getParentType() { + return "ViewGroup"; + } - @NonNull - @Override - public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { - return new ProteusViewPager(context); - } + @NonNull + @Override + public ProteusView createView(@NonNull ProteusContext context, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewGroup parent, int dataIndex) { + return new ProteusViewPager(context); + } - @NonNull - @Override - public ProteusView.Manager createViewManager(@NonNull ProteusContext context, @NonNull ProteusView view, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewTypeParser caller, @Nullable ViewGroup parent, int dataIndex) { - DataContext dataContext = createDataContext(context, layout, data, parent, dataIndex); - return new AdapterBasedViewManager(context, null != caller ? caller : this, view.getAsView(), layout, dataContext); - } + @NonNull + @Override + public ProteusView.Manager createViewManager(@NonNull ProteusContext context, @NonNull ProteusView view, @NonNull Layout layout, @NonNull ObjectValue data, @Nullable ViewTypeParser caller, @Nullable ViewGroup parent, int dataIndex) { + DataContext dataContext = createDataContext(context, layout, data, parent, dataIndex); + return new AdapterBasedViewManager(context, null != caller ? caller : this, view.getAsView(), layout, dataContext); + } - @Override - protected void addAttributeProcessors() { + @Override + protected void addAttributeProcessors() { - } + } }