├── .github
├── ISSUE_TEMPLATE
└── PULL_REQUEST_TEMPLATE
├── .gitignore
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── yahoo
│ │ └── android
│ │ └── dlayout
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── yahoo
│ │ │ └── android
│ │ │ └── dlayout
│ │ │ └── demo
│ │ │ ├── activity
│ │ │ └── LauncherActivity.java
│ │ │ ├── app
│ │ │ └── DynamicLayoutApplication.java
│ │ │ ├── cache
│ │ │ └── LayoutCache.java
│ │ │ └── http
│ │ │ └── Httpd.java
│ └── res
│ │ ├── layout
│ │ ├── activity_launcher.xml
│ │ ├── builtin_layout.xml
│ │ ├── dynamic_choice_layout.xml
│ │ └── fragment_launcher.xml
│ │ ├── menu
│ │ └── menu_launcher.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── raw
│ │ ├── dynamic_layout_01.bin
│ │ └── dynamic_layout_02.bin
│ │ ├── values-v21
│ │ └── styles.xml
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── yahoo
│ └── android
│ └── dlayout
│ └── ExampleUnitTest.java
├── build.gradle
├── dynamic-layout-loader
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── yahoo
│ │ └── android
│ │ └── dlayout
│ │ └── LayoutLoader.java
│ └── res
│ └── values
│ └── strings.xml
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── layout-designer
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── yahoo
│ │ └── android
│ │ └── designer
│ │ └── MainActivity.java
│ └── res
│ ├── layout
│ ├── activity_main.xml
│ ├── dynamic_layout_01.xml
│ └── dynamic_layout_02.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
└── settings.gradle
/.github/ISSUE_TEMPLATE:
--------------------------------------------------------------------------------
1 | ### Expected Behaviour
2 |
3 |
4 | ### Actual Behaviour
5 |
6 |
7 | ### Steps to Reproduce
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE:
--------------------------------------------------------------------------------
1 | For Issue # .
2 |
3 | #### Changes
4 |
5 | .
6 | .
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/
5 | /.idea/workspace.xml
6 | /.idea/libraries
7 | .DS_Store
8 | /build
9 | /captures
10 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
10 |
11 | "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
12 |
13 | "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
14 |
15 | "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
16 |
17 | "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
18 |
19 | "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
20 |
21 | "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
22 |
23 | "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
24 |
25 | "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
26 |
27 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
28 |
29 | 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
30 |
31 | 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
32 |
33 | 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
34 |
35 | (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
36 |
37 | (b) You must cause any modified files to carry prominent notices stating that You changed the files; and
38 |
39 | (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
40 |
41 | (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
42 |
43 | You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
44 |
45 | 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
46 |
47 | 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
48 |
49 | 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, eitherf any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
50 |
51 | 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
52 |
53 | END OF TERMS AND CONDITIONS
54 |
55 | APPENDIX: How to apply the Apache License to your work.
56 |
57 | To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
58 |
59 | Copyright [yyyy] [name of copyright owner]
60 |
61 | Licensed under the Apache License, Version 2.0 (the "License");
62 | you may not use this file except in compliance with the License.
63 | You may obtain a copy of the License at
64 |
65 | http://www.apache.org/licenses/LICENSE-2.0
66 |
67 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
68 |
69 | See the License for the specific language governing permissions and limitations under the License.
70 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Dynamic Layout Loader
2 |
3 | `LayoutInflater` cannot load layouts that are plain XML. It can also not load layouts that are not loaded from resources (`R.layout.{blah}`).
4 |
5 | Dynamic Layout Loader uses a non-public API (available and unchanged since API Level 1) to help load compiled layouts from any source - local filesystem, network etc. All it needs is `InputStream` to load the data or raw data as `byte[]`.
6 |
7 | ## Repository Structure
8 |
9 | * `dynamic-layout-loader`: Provides the loader. See [`LayoutLoader`](dynamic-layout-loader/src/main/java/com/yahoo/android/dlayout/LayoutLoader.java) class.
10 | * `app`: Sample app demonstrating the use of the loader.
11 | * `layout-designer`: Accompanying app to create layouts independent of the target app - to demonstrate full capabilities.
12 |
13 | ## Constraints
14 |
15 | 1. The resource references do not work. For example, you cannot use `@drawable/icon` or `@string/name` etc in the layout.
16 | 1. As a corollary, the ids do not work. You cannot use `@id/another_element` in layout or `findViewById` in code. Use `android:tag` and `findViewWithTag`.
17 | 1. The current implementation does not support styles and theme. You cannot use `style` attribute in the layout.
18 |
19 |
20 | ## License
21 |
22 | The use and distribution terms for this software are covered by the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0.html).
23 |
24 | See file [LICENSE](LICENSE) accompanying the code.
25 |
26 | ## Related Links
27 |
28 | * Presentation at SF Droidcon 2016: [Original - Keynote](http://bit.ly/1o01Znz) and [PDF](http://bit.ly/1Uv6MLY)
29 |
30 |
31 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | allprojects {
4 | repositories {
5 | jcenter()
6 | mavenCentral()
7 | }
8 | }
9 |
10 | android {
11 | compileSdkVersion 23
12 | buildToolsVersion "23.0.2"
13 |
14 | defaultConfig {
15 | applicationId "com.yahoo.android.dlayout.demo"
16 | minSdkVersion 16
17 | targetSdkVersion 23
18 | versionCode 1
19 | versionName "1.0"
20 | }
21 | buildTypes {
22 | release {
23 | minifyEnabled false
24 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
25 | }
26 | }
27 | }
28 |
29 | dependencies {
30 | compile fileTree(dir: 'libs', include: ['*.jar'])
31 | compile project(':dynamic-layout-loader')
32 |
33 | testCompile 'junit:junit:4.12'
34 | compile 'com.android.support:appcompat-v7:23.2.1'
35 | compile 'com.android.support:design:23.2.1'
36 | compile 'org.nanohttpd:nanohttpd:2.3.0'
37 | compile 'com.squareup.okhttp3:okhttp:3.2.0'
38 | compile 'com.squareup.picasso:picasso:2.5.2'
39 | compile 'com.google.android.gms:play-services-appindexing:8.1.0'
40 | }
41 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/vgaurav/Desktop/all/downloads/adt/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/yahoo/android/dlayout/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.yahoo.android.dlayout;
2 |
3 | import android.test.ApplicationTestCase;
4 |
5 | import com.yahoo.android.dlayout.demo.app.DynamicLayoutApplication;
6 |
7 | /**
8 | * Testing Fundamentals
9 | */
10 | public class ApplicationTest extends ApplicationTestCase {
11 | public ApplicationTest() {
12 | super(DynamicLayoutApplication.class);
13 | }
14 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
13 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yahoo/android/dlayout/demo/activity/LauncherActivity.java:
--------------------------------------------------------------------------------
1 | package com.yahoo.android.dlayout.demo.activity;
2 |
3 | import android.app.AlertDialog;
4 | import android.content.Context;
5 | import android.content.DialogInterface;
6 | import android.support.design.widget.TabLayout;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.widget.Toolbar;
9 |
10 | import android.support.v4.app.Fragment;
11 | import android.support.v4.app.FragmentManager;
12 | import android.support.v4.app.FragmentPagerAdapter;
13 | import android.support.v4.view.ViewPager;
14 | import android.os.Bundle;
15 | import android.view.LayoutInflater;
16 | import android.view.Menu;
17 | import android.view.View;
18 | import android.view.ViewGroup;
19 |
20 | import android.widget.ImageView;
21 | import android.widget.LinearLayout;
22 | import android.widget.RadioGroup;
23 |
24 | import com.google.android.gms.appindexing.Action;
25 | import com.google.android.gms.appindexing.AppIndex;
26 | import com.google.android.gms.common.api.GoogleApiClient;
27 | import com.yahoo.android.dlayout.demo.R;
28 | import com.yahoo.android.dlayout.demo.app.DynamicLayoutApplication;
29 | import com.squareup.picasso.Picasso;
30 |
31 | public class LauncherActivity extends AppCompatActivity {
32 |
33 | private SectionsPagerAdapter mSectionsPagerAdapter;
34 | private ViewPager mViewPager;
35 |
36 | private static String[] imageURLs = {
37 | "https://raw.githubusercontent.com/gvaish/images/master/01.jpg",
38 | "https://raw.githubusercontent.com/gvaish/images/master/02.png",
39 | "https://raw.githubusercontent.com/gvaish/images/master/03.jpg"
40 | };
41 |
42 | @Override
43 | protected void onCreate(Bundle savedInstanceState) {
44 | super.onCreate(savedInstanceState);
45 | setContentView(R.layout.activity_launcher);
46 |
47 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
48 | setSupportActionBar(toolbar);
49 | mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
50 |
51 | mViewPager = (ViewPager) findViewById(R.id.container);
52 | mViewPager.setAdapter(mSectionsPagerAdapter);
53 |
54 | TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
55 | tabLayout.setupWithViewPager(mViewPager);
56 | }
57 |
58 |
59 | @Override
60 | public boolean onCreateOptionsMenu(Menu menu) {
61 | return false;
62 | }
63 |
64 | public static class PlaceholderFragment extends Fragment {
65 | private static final String ARG_SECTION_NUMBER = "section_number";
66 | private DynamicLayoutApplication app;
67 |
68 | public static PlaceholderFragment newInstance(int sectionNumber) {
69 | PlaceholderFragment fragment = new PlaceholderFragment();
70 | Bundle args = new Bundle();
71 | args.putInt(ARG_SECTION_NUMBER, sectionNumber);
72 | fragment.setArguments(args);
73 | return fragment;
74 | }
75 |
76 | @Override
77 | public void onAttach(Context context) {
78 | super.onAttach(context);
79 | this.app = (DynamicLayoutApplication) context.getApplicationContext();
80 | }
81 |
82 | @Override
83 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
84 | Bundle savedInstanceState) {
85 | int sectionNumber = getArguments().getInt(ARG_SECTION_NUMBER);
86 | switch(sectionNumber) {
87 | case 1:
88 | return populate(inflater.inflate(R.layout.builtin_layout, container, false), sectionNumber, "1");
89 | case 2:
90 | case 3:
91 | return populate(loadViewFromNetwork(sectionNumber, container), sectionNumber, String.valueOf(sectionNumber));
92 | case 4:
93 | return populate(loadDynamically(inflater, container, sectionNumber), sectionNumber, String.valueOf(sectionNumber));
94 | }
95 | return null;
96 | }
97 |
98 | protected View loadDynamically(final LayoutInflater inflater, final ViewGroup container, int sectionNumber) {
99 | View root = inflater.inflate(R.layout.dynamic_choice_layout, container, false);
100 | RadioGroup rg = (RadioGroup) root.findViewById(R.id.choice);
101 | final ViewGroup fl = (ViewGroup) root.findViewById(R.id.container);
102 | rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
103 | @Override
104 | public void onCheckedChanged(RadioGroup group, int checkedId) {
105 | View v = null;
106 | switch (checkedId) {
107 | case R.id.choice1:
108 | v = createDynamicView(0, inflater, fl, "4.1");
109 | break;
110 | case R.id.choice2:
111 | v = createDynamicView(1, inflater, fl, "4.2");
112 | break;
113 | case R.id.choice3:
114 | v = createDynamicView(2, inflater, fl, "4.3");
115 | break;
116 | }
117 | fl.removeAllViews();;
118 | if(v != null) {
119 | fl.addView(v);
120 | }
121 | }
122 | });
123 | return root;
124 | }
125 |
126 | protected View createDynamicView(int index, LayoutInflater inflater, ViewGroup container, String msgSuffix) {
127 | View rv = null;
128 | switch (index) {
129 | case 0:
130 | rv = inflater.inflate(R.layout.builtin_layout, container, false);
131 | break;
132 | case 1:
133 | case 2:
134 | rv = loadViewFromNetwork(index + 1, container);
135 | break;
136 | }
137 | if(rv != null) {
138 | populate(rv, index + 1, msgSuffix);
139 | }
140 | return rv;
141 | }
142 |
143 | private View loadViewFromNetwork(int sectionNumber, ViewGroup container) {
144 | byte[] data = app.getLayoutCache().get("http://127.0.0.1:8888/0" + (sectionNumber - 1));
145 | return app.getLayoutLoader().load(data, getActivity(), container, false);
146 | }
147 |
148 | private View populate(View view, final int imageNo, final String msgSuffix) {
149 | ImageView iv = (ImageView) view.findViewWithTag("image");
150 | if (iv != null) {
151 | Picasso.with(getActivity()).load(imageURLs[imageNo - 1]).into(iv);
152 | }
153 |
154 | View action = view.findViewWithTag("action");
155 | if (action != null) {
156 | action.setOnClickListener(new View.OnClickListener() {
157 | @Override
158 | public void onClick(View v) {
159 | new AlertDialog.Builder(getActivity())
160 | .setTitle("Action Performed at " + msgSuffix)
161 | .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
162 | @Override
163 | public void onClick(DialogInterface dialog, int which) {
164 | dialog.dismiss();
165 | }
166 | })
167 | .create().show();
168 | }
169 | });
170 | }
171 |
172 | return view;
173 | }
174 | }
175 |
176 | public class SectionsPagerAdapter extends FragmentPagerAdapter {
177 |
178 | public SectionsPagerAdapter(FragmentManager fm) {
179 | super(fm);
180 | }
181 |
182 | @Override
183 | public Fragment getItem(int position) {
184 | return PlaceholderFragment.newInstance(position + 1);
185 | }
186 |
187 | @Override
188 | public int getCount() {
189 | return 4;
190 | }
191 |
192 | @Override
193 | public CharSequence getPageTitle(int position) {
194 | switch (position) {
195 | case 0:
196 | return "App";
197 | case 1:
198 | return "Remote 1";
199 | case 2:
200 | return "Remote 2";
201 | case 3:
202 | return "Choice";
203 | }
204 | return null;
205 | }
206 | }
207 | }
208 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yahoo/android/dlayout/demo/app/DynamicLayoutApplication.java:
--------------------------------------------------------------------------------
1 | package com.yahoo.android.dlayout.demo.app;
2 |
3 | import android.app.Application;
4 | import android.util.Log;
5 |
6 | import com.yahoo.android.dlayout.LayoutLoader;
7 | import com.yahoo.android.dlayout.demo.cache.LayoutCache;
8 | import com.yahoo.android.dlayout.demo.http.Httpd;
9 |
10 | import java.io.IOException;
11 |
12 | import okhttp3.Call;
13 | import okhttp3.Callback;
14 | import okhttp3.Interceptor;
15 | import okhttp3.OkHttpClient;
16 | import okhttp3.Request;
17 | import okhttp3.Response;
18 |
19 | /**
20 | * Created by vgaurav on 3/15/16.
21 | */
22 | public class DynamicLayoutApplication extends Application {
23 |
24 | private LayoutLoader layoutLoader;
25 | private Httpd httpd;
26 | private OkHttpClient httpClient;
27 | private LayoutCache layoutCache;
28 |
29 | @Override
30 | public void onCreate() {
31 | super.onCreate();
32 | layoutLoader = new LayoutLoader().initialize();
33 | startServer();
34 | layoutCache = new LayoutCache();
35 | initializeLayoutCache(getLayoutCache());
36 | }
37 |
38 | private void initializeLayoutCache(LayoutCache layoutCache) {
39 |
40 | for(int i = 1; i <= 2; i++) {
41 | String url = "http://127.0.0.1:8888/0" + i;
42 |
43 | Request req = new Request.Builder().url(url).get().build();
44 | OkHttpClient client = getHttpClient();
45 |
46 | client.newCall(req).enqueue(new Callback() {
47 | @Override
48 | public void onFailure(Call call, IOException e) {
49 | Log.w("DLayout", "[FAILED] Loaded Layout: " + call.request().url(), e);
50 | }
51 |
52 | @Override
53 | public void onResponse(Call call, Response response) throws IOException {
54 | byte[] data = response.body().bytes();
55 | String url = response.request().url().toString();
56 | Log.w("DLayout", "Loaded Layout: " + url);
57 | getLayoutCache().put(url, data);
58 | }
59 | });
60 | }
61 |
62 | }
63 |
64 | public LayoutLoader getLayoutLoader() {
65 | return layoutLoader;
66 | }
67 |
68 | public void startServer() {
69 | if(httpd == null) {
70 | httpd = new Httpd(this, 8888);
71 | try {
72 | httpd.start();
73 | Log.d("DLayout", "Server started...");
74 | } catch (IOException e) {
75 | Log.d("DLayout", "Server failed to start", e);
76 | }
77 | }
78 | }
79 |
80 | public void stopServer() {
81 | if(httpd != null) {
82 | httpd.stop();
83 | httpd = null;
84 | }
85 | }
86 |
87 | public OkHttpClient getHttpClient() {
88 | if(httpClient == null) {
89 | httpClient = new OkHttpClient.Builder()
90 | .addInterceptor(new Interceptor() {
91 | @Override
92 | public Response intercept(Interceptor.Chain chain) throws IOException {
93 | Request req = chain.request();
94 | Log.d("DLayout", "[http-request] url=" + req.url());
95 | return chain.proceed(req);
96 | }
97 | }).build();
98 | }
99 | return httpClient;
100 | }
101 |
102 | public LayoutCache getLayoutCache() {
103 | return layoutCache;
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yahoo/android/dlayout/demo/cache/LayoutCache.java:
--------------------------------------------------------------------------------
1 | package com.yahoo.android.dlayout.demo.cache;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | /**
7 | * Created by vgaurav on 3/15/16.
8 | */
9 | public class LayoutCache {
10 |
11 | private Map cache;
12 |
13 | public LayoutCache() {
14 | cache = new HashMap<>();
15 | }
16 |
17 | public void put(String url, byte[] data) {
18 | cache.put(url, data);
19 | }
20 |
21 | public byte[] get(String url) {
22 | return cache.get(url);
23 | }
24 |
25 | public void remove(String url) {
26 | cache.remove(url);
27 | }
28 |
29 | public void clear() {
30 | cache.clear();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yahoo/android/dlayout/demo/http/Httpd.java:
--------------------------------------------------------------------------------
1 | package com.yahoo.android.dlayout.demo.http;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.util.Log;
6 |
7 | import com.yahoo.android.dlayout.demo.R;
8 |
9 | import java.io.IOException;
10 | import java.io.InputStream;
11 |
12 | import fi.iki.elonen.NanoHTTPD;
13 |
14 | /**
15 | * Created by vgaurav on 3/15/16.
16 | */
17 | public class Httpd extends NanoHTTPD {
18 | private final Context context;
19 |
20 | public Httpd(Context ctx, int port) {
21 | super("127.0.0.1", port);
22 | this.context = ctx;
23 | }
24 |
25 | @Override
26 | public void start() throws IOException {
27 | super.start();
28 | Log.d("DLayout", "server started");
29 | }
30 |
31 | @Override
32 | public Response serve(IHTTPSession session) {
33 | String uri = session.getUri();
34 |
35 | Log.d("DLayout", "[Server::serve] uri=" + uri);
36 |
37 | Resources res = context.getResources();
38 | InputStream input = null;
39 |
40 | if("/01".equals(uri)) {
41 | input = res.openRawResource(R.raw.dynamic_layout_01);
42 | } else {
43 | input = res.openRawResource(R.raw.dynamic_layout_02);
44 | }
45 | return newChunkedResponse(Response.Status.OK, "application/octet-stream", input);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
17 |
18 |
25 |
26 |
27 |
28 |
32 |
33 |
34 |
35 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/builtin_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
21 |
22 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/dynamic_choice_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
20 |
26 |
32 |
33 |
34 |
38 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_launcher.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_launcher.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gvaish/android-dynamic-layouts/ca7ede2a3008955d9efb3fba4f8c630fcc67450c/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gvaish/android-dynamic-layouts/ca7ede2a3008955d9efb3fba4f8c630fcc67450c/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gvaish/android-dynamic-layouts/ca7ede2a3008955d9efb3fba4f8c630fcc67450c/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gvaish/android-dynamic-layouts/ca7ede2a3008955d9efb3fba4f8c630fcc67450c/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gvaish/android-dynamic-layouts/ca7ede2a3008955d9efb3fba4f8c630fcc67450c/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/raw/dynamic_layout_01.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gvaish/android-dynamic-layouts/ca7ede2a3008955d9efb3fba4f8c630fcc67450c/app/src/main/res/raw/dynamic_layout_01.bin
--------------------------------------------------------------------------------
/app/src/main/res/raw/dynamic_layout_02.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gvaish/android-dynamic-layouts/ca7ede2a3008955d9efb3fba4f8c630fcc67450c/app/src/main/res/raw/dynamic_layout_02.bin
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 | 8dp
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Dynamic Layout Demo
3 | Dynamic Layout
4 | Settings
5 | Hello World from section: %1$d
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
13 |
14 |
17 |
18 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/test/java/com/yahoo/android/dlayout/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.yahoo.android.dlayout;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.1.0-alpha1'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | mavenCentral()
19 | }
20 | }
21 |
22 | task clean(type: Delete) {
23 | delete rootProject.buildDir
24 | }
25 |
--------------------------------------------------------------------------------
/dynamic-layout-loader/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/dynamic-layout-loader/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 16
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | testCompile 'junit:junit:4.12'
24 | compile 'com.android.support:appcompat-v7:23.2.1'
25 | }
26 |
--------------------------------------------------------------------------------
/dynamic-layout-loader/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/vgaurav/Desktop/all/downloads/adt/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/dynamic-layout-loader/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/dynamic-layout-loader/src/main/java/com/yahoo/android/dlayout/LayoutLoader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Yahoo Inc.
3 | *
4 | * Licensed under the terms of the Apache License, Version 2.
5 | * Please see LICENSE.txt in the project root for terms.
6 | */
7 | package com.yahoo.android.dlayout;
8 |
9 | import java.io.ByteArrayOutputStream;
10 | import java.io.IOException;
11 | import java.io.InputStream;
12 | import java.lang.reflect.Constructor;
13 | import java.lang.reflect.Method;
14 |
15 | import android.content.Context;
16 | import android.content.res.XmlResourceParser;
17 | import android.util.Log;
18 | import android.view.LayoutInflater;
19 | import android.view.View;
20 | import android.view.ViewGroup;
21 |
22 | /**
23 | * LayoutLoader helps you load compiled layouts from any source.
24 | *
25 | *
26 | * The layout can be loaded from either an {@link InputStream} or raw bytes.
27 | *
28 | *
29 | *
30 | * A typical application using {@link LayoutLoader} will have code similar to that given below:
31 | *
124 | * This method must be called before {@link #load(byte[], Context, ViewGroup, boolean)}
125 | * or {@link #load(InputStream, Context, ViewGroup, boolean)} can be used.
126 | *
127 | *
128 | *
129 | * The method is reentrant (can be called multiple times) and thread-safe.
130 | *
131 | *
132 | *
133 | * This method has been provided for lazy initialization.
134 | *
195 | * It returns the {@link View} if it can be inflated, null otherwise.
196 | *
197 | *
198 | *
199 | * It internally uses {@link LayoutInflater#inflate(int, ViewGroup, boolean)}.
200 | * All semantics of the corresponding method apply.
201 | *
202 | *
203 | * @param input {@link InputStream} from where the contents of the compiled layout can be read
204 | * @param context {@link Context} to load the resources from
205 | * @param root Optional view to be the parent of the generated hierarchy (if
206 | * attachToRoot is true), or else simply an object that
207 | * provides a set of LayoutParams values for root of the returned
208 | * hierarchy (if attachToRoot is false.)
209 | * @param attachToRoot Whether the inflated hierarchy should be attached to
210 | * the root parameter? If false, root is only used to create the
211 | * correct subclass of LayoutParams for the root view in the XML.
212 | * @return The root View of the inflated hierarchy. If root was supplied and
213 | * attachToRoot is true, this is root; otherwise it is the root of
214 | * the inflated XML file.
215 | * @see #load(byte[], Context, ViewGroup, boolean)
216 | */
217 | public View load(InputStream input, Context context, ViewGroup root, boolean attachToRoot) {
218 | View rv = null;
219 |
220 | if(ready && xmlBlockCtor != null && newParserMethod != null) {
221 | byte[] data = readAll(input);
222 | rv = load(data, context, root, attachToRoot);
223 | }
224 |
225 | return rv;
226 | }
227 |
228 | /**
229 | * Loads the template from the given {@link InputStream}.
230 | *
231 | *
232 | * It returns the {@link View} if it can be inflated, null otherwise.
233 | *
234 | *
235 | *
236 | * It internally uses {@link LayoutInflater#inflate(int, ViewGroup, boolean)}.
237 | * All semantics of the corresponding method apply.
238 | *
239 | *
240 | * @param data Raw data of the compiled layout.
241 | * @param context {@link Context} to load the resources from
242 | * @param root Optional view to be the parent of the generated hierarchy (if
243 | * attachToRoot is true), or else simply an object that
244 | * provides a set of LayoutParams values for root of the returned
245 | * hierarchy (if attachToRoot is false.)
246 | * @param attachToRoot Whether the inflated hierarchy should be attached to
247 | * the root parameter? If false, root is only used to create the
248 | * correct subclass of LayoutParams for the root view in the XML.
249 | * @return The root View of the inflated hierarchy. If root was supplied and
250 | * attachToRoot is true, this is root; otherwise it is the root of
251 | * the inflated XML file.
252 | * @see #load(InputStream, Context, ViewGroup, boolean)
253 | */
254 | public View load(byte[] data, Context context, ViewGroup root, boolean attachToRoot) {
255 | View rv = null;
256 | if(ready && xmlBlockCtor != null && newParserMethod != null && data != null) {
257 | try {
258 | Object xmlBlock = xmlBlockCtor.newInstance(data);
259 | XmlResourceParser parser = (XmlResourceParser) newParserMethod.invoke(xmlBlock);
260 |
261 | LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
262 | rv = inflater.inflate(parser, root, attachToRoot);
263 | } catch(RuntimeException e) {
264 | Log.e(TAG, "Failed loading layout", e);
265 | } catch(Exception e) {
266 | Log.e(TAG, "Failed loading layout", e);
267 | }
268 | }
269 | return rv;
270 | }
271 |
272 | private byte[] readAll(InputStream input) {
273 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
274 | byte[] buffer = new byte[1024];
275 | int read;
276 | byte[] rv = null;
277 |
278 | try {
279 | read = input.read(buffer, 0, buffer.length);
280 | while(read >= 0) {
281 | baos.write(buffer, 0, read);
282 | read = input.read(buffer, 0, buffer.length);
283 | }
284 | rv = baos.toByteArray();
285 | } catch(IOException e) {
286 | Log.e(TAG, "Failed reading layout content", e);
287 | }
288 |
289 | return rv;
290 | }
291 | }
--------------------------------------------------------------------------------
/dynamic-layout-loader/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | dlayout
3 |
4 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gvaish/android-dynamic-layouts/ca7ede2a3008955d9efb3fba4f8c630fcc67450c/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/layout-designer/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/layout-designer/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.yahoo.android.designer"
9 | minSdkVersion 16
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.2.1'
26 | }
27 |
--------------------------------------------------------------------------------
/layout-designer/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/vgaurav/Desktop/all/downloads/adt/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/layout-designer/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/layout-designer/src/main/java/com/yahoo/android/designer/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.yahoo.android.designer;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 |
6 | import com.yahoo.android.designer.R;
7 |
8 | public class MainActivity extends Activity {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.dynamic_layout_02);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/layout-designer/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
17 |
18 |
--------------------------------------------------------------------------------
/layout-designer/src/main/res/layout/dynamic_layout_01.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
21 |
22 |
27 |
--------------------------------------------------------------------------------
/layout-designer/src/main/res/layout/dynamic_layout_02.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
20 |
21 |
27 |
--------------------------------------------------------------------------------
/layout-designer/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gvaish/android-dynamic-layouts/ca7ede2a3008955d9efb3fba4f8c630fcc67450c/layout-designer/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/layout-designer/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gvaish/android-dynamic-layouts/ca7ede2a3008955d9efb3fba4f8c630fcc67450c/layout-designer/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/layout-designer/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gvaish/android-dynamic-layouts/ca7ede2a3008955d9efb3fba4f8c630fcc67450c/layout-designer/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/layout-designer/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gvaish/android-dynamic-layouts/ca7ede2a3008955d9efb3fba4f8c630fcc67450c/layout-designer/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/layout-designer/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gvaish/android-dynamic-layouts/ca7ede2a3008955d9efb3fba4f8c630fcc67450c/layout-designer/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/layout-designer/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/layout-designer/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/layout-designer/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/layout-designer/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | LayoutDesigner
3 |
4 |
--------------------------------------------------------------------------------
/layout-designer/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':dynamic-layout-loader', ':layout-designer'
2 |
--------------------------------------------------------------------------------