├── .gitignore
├── .idea
└── vcs.xml
├── README.md
├── build.gradle
├── firelayout
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── com
│ └── fs
│ └── firelayout
│ ├── FireLayout.java
│ ├── FireView.java
│ ├── utils
│ ├── FireViewGenerator.java
│ └── FireViewUtils.java
│ ├── viewgroups
│ ├── FireLinearLayout.java
│ └── FireRelativeLayout.java
│ └── views
│ ├── FireButton.java
│ ├── FireEditText.java
│ ├── FireImageView.java
│ └── FireTextView.java
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── sample
├── .gitignore
├── build.gradle
├── firelayoutSampleConf.json
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── fs
│ │ └── firelayout
│ │ └── sample
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── fs
│ │ │ └── firelayout
│ │ │ └── sample
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── drawable-hdpi
│ │ └── ic_action_name.png
│ │ ├── drawable-mdpi
│ │ └── ic_action_name.png
│ │ ├── drawable-xhdpi
│ │ └── ic_action_name.png
│ │ ├── drawable-xxhdpi
│ │ └── ic_action_name.png
│ │ ├── layout
│ │ └── activity_main.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
│ └── test
│ └── java
│ └── com
│ └── fs
│ └── firelayout
│ └── sample
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # FireLayout (Android)
2 |
3 | ## Description
4 | FireLayout is a CoordinatorLayout linked to its refence on your Firebase Real-Time Database. You can generate your own layout through firebase console.
5 |
6 | ## Importing with Gradle
7 | ```
8 | compile 'com.fs.firelayout:firelayout:0.2.5'
9 | ```
10 |
11 | ## Importing with Maven
12 | ```maven
13 |
14 | com.fs.firelayout
15 | firelayout
16 | 0.2.5
17 | pom
18 |
19 | ```
20 | ## Setup
21 | Configure your project with Firebase in order to use Firebase-Database with the auto-generated json file. Use the firebase plugin built in Android Studio.
22 |
23 | ## How to
24 | Create an instance of FireLayout in your layout file or by java code.
25 |
26 | Example:
27 | ```xml
28 |
32 | ```
33 | Note: 'android:id' is mandatory! It's the reference in your firebase database.
34 |
35 | Now you have to instantiate the FireLayout:
36 | ```java
37 | ...
38 | FirebaseDatabase database = FirebaseDatabase.getInstance();
39 | FireLayout fireLayout = (FireLayout) findViewById(R.id.fire1);
40 |
41 | //if you want to listen events
42 | fireLayout.setEventsListener(new FireLayout.EventsListener() {
43 | @Override
44 | public void onFireLayoutChildClicked(View view) {
45 | //if you add a tag in your view, you can do some logic to identify the view
46 | }
47 |
48 | @Override
49 | public void onFireLayoutChildLongClicked(View view) {
50 | //if you add a tag in your view, you can do some logic to identify the view
51 | }
52 | });
53 |
54 | fireLayout.init(database);
55 | ...
56 | ```
57 | Now you're ready to build your own layout!
58 |
59 | Example (in sample app folder 'firelayoutSampleConf.json'):
60 |
61 | ```json
62 | {
63 | "fire1": {
64 | "relativelayout": {
65 | "layout_width": "match_parent",
66 | "layout_height": "match_parent",
67 | "padding": 5,
68 | "children": {
69 | "linearlayout": {
70 | "layout_width": "match_parent",
71 | "layout_height": "wrap_content",
72 | "orientation": "vertical",
73 | "center_in_parent": true,
74 | "gravity": "center",
75 | "children": {
76 | "imageview": {
77 | "tag": "img1",
78 | "layout_width": "wrap_content",
79 | "layout_height": "wrap_content",
80 | "srcUrl": "https://cdn4.iconfinder.com/data/icons/google-i-o-2016/512/google_firebase-512.png",
81 | "srcError": "ic_action_name",
82 | "onClick": true
83 | },
84 | "textview": {
85 | "layout_width": "match_parent",
86 | "layout_height": "wrap_content",
87 | "text": "Hi, FireLayout!",
88 | "textColor": "#FFFFFF",
89 | "textSize": 20,
90 | "background": "#404040",
91 | "gravity": "center",
92 | "padding": 5,
93 | "onClick": true
94 | },
95 | "button": {
96 | "tag": "bt1",
97 | "layout_width": "wrap_content",
98 | "layout_height": "wrap_content",
99 | "text": "OK",
100 | "textColor": "#404040",
101 | "background": "#FFFFFF",
102 | "gravity": "center",
103 | "padding": 5,
104 | "margin_top": 10,
105 | "onClick": true,
106 | "onLongClick": true
107 | }
108 | }
109 | }
110 | }
111 | }
112 | }
113 | }
114 | ```
115 | Import your json in your Firebase database and you're done!
116 |
117 | ## Views
118 | This library is in development and I'm adding new attributes and views. I'll update the following list each update:
119 |
120 | Views :
121 |
122 | - All
123 |
124 | tag = "tag" (use it as identifier)
125 |
126 | layout_width = integer / "wrap_content" / "match_parent"
127 |
128 | layout_height = integer / "wrap_content" / "match_parent"
129 |
130 | background = "exadecimal_code", see example
131 |
132 | enable = true/false, default true
133 |
134 | visibility = "gone" / "invisible", default visible
135 |
136 | padding = integer (if exists, other padding values won't be effective)
137 |
138 | padding_top = integer
139 |
140 | padding_left = integer
141 |
142 | padding_right = integer
143 |
144 | padding_bottom = integer
145 |
146 | margin = integer (if exists, other margin values won't be effective)
147 |
148 | margin_top = integer
149 |
150 | margin_left = integer
151 |
152 | margin_right = integer
153 |
154 | margin_bottom = integer
155 |
156 | onClick = true/false, default false
157 |
158 | onLongClick = true/false, default false
159 |
160 | ViewGroups:
161 |
162 | - All:
163 |
164 | children = {"childviewname" : {}}
165 |
166 | - linearlayout (LinearLayout)
167 |
168 | orientation = "vertical" / "horizontal"
169 |
170 | gravity = "center" / "center_horizontal" / "center_vertical" / "bottom" / "top" / "left" / "right"
171 |
172 | - relativelayout (RelativeLayout)
173 |
174 | gravity = "center" / "center_horizontal" / "center_vertical" / "bottom" / "top" / "left" / "right"
175 |
176 | RelativeLayout has optional rules for its children, so in your child object you can add following (see json sample):
177 |
178 | align_parent_left = true / false, default false
179 |
180 | align_parent_top = true / false, default false
181 |
182 | align_parent_right = true / false, default false
183 |
184 | align_parent_bottom = true / false, default false
185 |
186 | align_parent_start = true / false, default false
187 |
188 | align_parent_end = true / false, default false
189 |
190 | center_in_parent = true / false, default false
191 |
192 | center_horizontal = true / false, default false
193 |
194 | center_vertical = true / false, default false
195 |
196 | Children Views :
197 |
198 | - textview (TextView)
199 |
200 | text = "text"
201 |
202 | textColor = "exadecimal_code", see example
203 |
204 | textSize = integer / double
205 |
206 | gravity = "center" / "center_horizontal" / "center_vertical" / "bottom" / "top" / "left" / "right"
207 |
208 | - edittext (EditText)
209 |
210 | text = "text"
211 |
212 | hint = "hint"
213 |
214 | textColor = "exadecimal_code", see example
215 |
216 | textSize = integer / double
217 |
218 | gravity = "center" / "center_horizontal" / "center_vertical" / "bottom" / "top" / "left" / "right"
219 |
220 | - button (Button)
221 |
222 | text = "text"
223 |
224 | textColor = "exadecimal_code", see example
225 |
226 | textSize = integer / double
227 |
228 | gravity = "center" / "center_horizontal" / "center_vertical" / "bottom" / "top" / "left" / "right"
229 |
230 | - imageview (ImageView)
231 |
232 | src = "name of drawable, in drawable folders"
233 |
234 | srcUrl = "url to image", not effective if src is set
235 |
236 | srcError = "name of drawable, in drawable folders", this is your image when srcUrl fails and It's not effective if src is set
237 |
238 | adjustViewBounds = boolean, default false
239 |
240 | scaleType = "scaletype", accepted values : "CENTER", "CENTER_CROP", "CENTER_INSIDE", "FIT_CENTER", "FIT_END", "FIT_START", "FIT_XY", "MATRIX". Default is CENTER_INSIDE.
241 |
242 | colorFilter = "exadecimal_code", see example
243 |
244 | maxHeight = number
245 |
246 | maxWidth = number
247 |
248 | ## LICENSE
249 |
250 | > Copyright 2016 Francesco Stranieri
251 |
252 | > Licensed under the Apache License, Version 2.0 (the "License");
253 | > you may not use this file except in compliance with the License.
254 | > You may obtain a copy of the License at
255 |
256 | > http://www.apache.org/licenses/LICENSE-2.0
257 |
258 | > Unless required by applicable law or agreed to in writing, software
259 | > distributed under the License is distributed on an "AS IS" BASIS,
260 | > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
261 | > See the License for the specific language governing permissions and
262 | > limitations under the License.
263 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.3'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | classpath 'com.google.gms:google-services:3.0.0'
13 |
14 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
15 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
16 | }
17 | }
18 |
19 | allprojects {
20 | repositories {
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/firelayout/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/firelayout/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | ext {
4 | bintrayRepo = 'maven'
5 | bintrayName = 'firelayout'
6 |
7 | publishedGroupId = 'com.fs.firelayout'
8 | libraryName = 'FireLayout'
9 | artifact = 'firelayout'
10 |
11 | libraryDescription = ''
12 |
13 | siteUrl = 'https://github.com/FStranieri/FireLayout'
14 | gitUrl = 'https://github.com/FStranieri/FireLayout.git'
15 |
16 | libraryVersion = '0.2.5'
17 |
18 | developerId = 'fstranieri'
19 | developerName = 'Francesco Stranieri'
20 | developerEmail = 'fer.stranieri@gmail.com'
21 |
22 | licenseName = 'The Apache Software License, Version 2.0'
23 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
24 | allLicenses = ["Apache-2.0"]
25 | }
26 |
27 | android {
28 | compileSdkVersion 25
29 | buildToolsVersion "24.0.2"
30 | defaultConfig {
31 | minSdkVersion 15
32 | targetSdkVersion 25
33 | versionCode 6
34 | versionName "0.2.5"
35 | }
36 | buildTypes {
37 | release {
38 | minifyEnabled false
39 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
40 | }
41 | }
42 | }
43 |
44 | dependencies {
45 | compile fileTree(dir: 'libs', include: ['*.jar'])
46 | compile 'com.android.support:appcompat-v7:25.0.1'
47 | compile 'com.android.support:design:25.0.1'
48 | compile 'com.google.firebase:firebase-database:10.0.1'
49 | compile 'com.android.volley:volley:1.0.0'
50 | }
51 |
52 | apply plugin: 'com.google.gms.google-services'
53 |
54 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
55 | apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
56 |
57 |
--------------------------------------------------------------------------------
/firelayout/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/Francesco/Library/Android/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 |
--------------------------------------------------------------------------------
/firelayout/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/firelayout/src/main/java/com/fs/firelayout/FireLayout.java:
--------------------------------------------------------------------------------
1 | package com.fs.firelayout;
2 |
3 | import android.content.Context;
4 | import android.support.design.widget.CoordinatorLayout;
5 | import android.util.AttributeSet;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import com.fs.firelayout.utils.FireViewGenerator;
10 | import com.fs.firelayout.utils.FireViewUtils;
11 | import com.google.firebase.database.DataSnapshot;
12 | import com.google.firebase.database.DatabaseError;
13 | import com.google.firebase.database.DatabaseReference;
14 | import com.google.firebase.database.FirebaseDatabase;
15 | import com.google.firebase.database.ValueEventListener;
16 |
17 | import java.lang.reflect.InvocationTargetException;
18 | import java.util.HashMap;
19 |
20 | /**
21 | * Created by Francesco on 22/01/17.
22 | */
23 |
24 | public class FireLayout extends CoordinatorLayout {
25 |
26 | EventsListener listener;
27 |
28 | public FireLayout(Context context) {
29 | super(context);
30 | }
31 |
32 | public FireLayout(Context context, AttributeSet attrs) {
33 | super(context, attrs);
34 | }
35 |
36 | public FireLayout(Context context, AttributeSet attrs, int defStyleAttr) {
37 | super(context, attrs, defStyleAttr);
38 | }
39 |
40 | public void init(FirebaseDatabase firebaseDatabase) {
41 | if (getId() != NO_ID) {
42 | String id = getResources().getResourceName(getId());
43 | DatabaseReference databaseReference = firebaseDatabase.getReference(id.substring(id.lastIndexOf("/")));
44 |
45 | databaseReference.addValueEventListener(new ValueEventListener() {
46 | @Override
47 | public void onDataChange(DataSnapshot dataSnapshot) {
48 | if (dataSnapshot != null && dataSnapshot.getValue() instanceof HashMap) {
49 | removeAllViews();
50 | checkLayout(FireLayout.this, (HashMap) dataSnapshot.getValue());
51 | }
52 | }
53 |
54 | @Override
55 | public void onCancelled(DatabaseError databaseError) {
56 |
57 | }
58 | });
59 | }
60 | }
61 |
62 | private void checkLayout(ViewGroup parent, HashMap map) {
63 | if (map != null) {
64 | for (String key : map.keySet()) {
65 | Object childMap = map.get(key);
66 | if (childMap != null && childMap instanceof HashMap) {
67 | View view = getRealView(key, (HashMap) childMap);
68 |
69 | if (view != null)
70 | {
71 | FireViewUtils.setLayoutParamsForParent(parent, view, (HashMap) childMap);
72 | parent.addView(view);
73 | }
74 | }
75 | }
76 | }
77 | }
78 |
79 | private View getRealView(String name, HashMap map) {
80 | View view = null;
81 | FireView fireview = null;
82 |
83 | FireViewGenerator fireViewGenerator = FireViewGenerator.getFireView(name);
84 |
85 | if (fireViewGenerator != null) {
86 | try {
87 | fireview = (fireViewGenerator.viewClass.getConstructor(Context.class, HashMap.class).newInstance(getContext(), map));
88 | } catch (InstantiationException e) {
89 | e.printStackTrace();
90 | } catch (IllegalAccessException e) {
91 | e.printStackTrace();
92 | } catch (InvocationTargetException e) {
93 | e.printStackTrace();
94 | } catch (NoSuchMethodException e) {
95 | e.printStackTrace();
96 | }
97 |
98 | if(fireview != null)
99 | {
100 | if(listener != null)
101 | fireview.setEventsListener(listener);
102 |
103 | view = fireview.getView();
104 | }
105 |
106 | if (fireViewGenerator.isViewGroup && map.get("children") != null && map.get("children") instanceof HashMap)
107 | checkLayout((ViewGroup) view, (HashMap) map.get("children"));
108 | }
109 |
110 | return view;
111 | }
112 |
113 | public void setEventsListener(EventsListener listener){
114 | this.listener = listener;
115 | }
116 |
117 | public interface EventsListener {
118 | void onFireLayoutChildClicked(View view);
119 | void onFireLayoutChildLongClicked(View view);
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/firelayout/src/main/java/com/fs/firelayout/FireView.java:
--------------------------------------------------------------------------------
1 | package com.fs.firelayout;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.graphics.Color;
6 | import android.text.TextUtils;
7 | import android.view.Gravity;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.RelativeLayout;
11 |
12 | import com.fs.firelayout.utils.FireViewUtils;
13 |
14 | import java.util.HashMap;
15 |
16 | /**
17 | * Created by Francesco on 22/01/17.
18 | */
19 |
20 | public abstract class FireView {
21 | protected HashMap attributesMap;
22 | View view;
23 |
24 | public void init(Context context, HashMap map) {
25 | this.attributesMap = map;
26 | view = generateView(context);
27 |
28 | resolveLayoutParams();
29 |
30 | checkTag();
31 | checkPadding();
32 |
33 | String color = FireViewUtils.getValue(attributesMap.get("background"), null);
34 | if (color != null)
35 | view.setBackgroundColor(Color.parseColor(color));
36 |
37 | view.setEnabled(FireViewUtils.getValue(attributesMap.get("enable"), true));
38 |
39 | view.setVisibility(getVisibility());
40 | }
41 |
42 | private void checkTag() {
43 | String tag = FireViewUtils.getValue(attributesMap.get("tag"), "");
44 |
45 | if (!TextUtils.isEmpty(tag))
46 | view.setTag(tag);
47 | }
48 |
49 | private void checkPadding() {
50 | if (attributesMap.get("padding") != null) {
51 | int padding = FireViewUtils.getValue(attributesMap.get("padding"), 0).intValue();
52 | view.setPadding(padding, padding, padding, padding);
53 | } else
54 | view.setPadding(FireViewUtils.getValue(attributesMap.get("padding_left"), 0).intValue(), FireViewUtils.getValue(attributesMap.get("padding_top"), 0).intValue(), FireViewUtils.getValue(attributesMap.get("padding_right"), 0).intValue(), FireViewUtils.getValue(attributesMap.get("padding_bottom"), 0).intValue());
55 | }
56 |
57 | private void resolveLayoutParams() {
58 | ViewGroup.MarginLayoutParams marginLayoutParams = new ViewGroup.MarginLayoutParams(getSize(attributesMap.get("layout_width")), getSize(attributesMap.get("layout_height")));
59 |
60 | if (attributesMap.get("margin") != null) {
61 | int margin = FireViewUtils.getValue(attributesMap.get("margin"), 0).intValue();
62 | marginLayoutParams.setMargins(margin, margin, margin, margin);
63 | } else
64 | marginLayoutParams.setMargins(FireViewUtils.getValue(attributesMap.get("margin_left"), 0).intValue(), FireViewUtils.getValue(attributesMap.get("margin_top"), 0).intValue(), FireViewUtils.getValue(attributesMap.get("margin_right"), 0).intValue(), FireViewUtils.getValue(attributesMap.get("margin_bottom"), 0).intValue());
65 |
66 | view.setLayoutParams(marginLayoutParams);
67 | }
68 |
69 | private int getSize(Object size) {
70 | if (size != null) {
71 | if (size instanceof Number)
72 | return ((Number) size).intValue();
73 | else if (size instanceof String) {
74 | switch ((String) size) {
75 | case "wrap_content":
76 | return ViewGroup.LayoutParams.WRAP_CONTENT;
77 | case "match_parent":
78 | return ViewGroup.LayoutParams.MATCH_PARENT;
79 | }
80 | }
81 | }
82 |
83 | return ViewGroup.LayoutParams.WRAP_CONTENT;
84 | }
85 |
86 | int getVisibility() {
87 | Object visibility = attributesMap.get("visibility");
88 | if (visibility != null && visibility instanceof String && !TextUtils.isEmpty((String) visibility)) {
89 | switch ((String) visibility) {
90 | case "gone":
91 | return View.GONE;
92 | case "invisible":
93 | return View.INVISIBLE;
94 | }
95 | }
96 |
97 | return View.VISIBLE;
98 | }
99 |
100 | //TODO: MORE KINDS OF GRAVITY
101 | protected int getGravity(String key) {
102 | Object gravity = attributesMap.get(key);
103 | if (gravity != null && gravity instanceof String && !TextUtils.isEmpty((String) gravity)) {
104 | switch ((String) gravity) {
105 | case "center":
106 | return Gravity.CENTER;
107 | case "center_horizontal":
108 | return Gravity.CENTER_HORIZONTAL;
109 | case "center_vertical":
110 | return Gravity.CENTER_VERTICAL;
111 | case "top":
112 | return Gravity.TOP;
113 | case "right":
114 | return Gravity.RIGHT;
115 | case "bottom":
116 | return Gravity.BOTTOM;
117 | case "left":
118 | return Gravity.LEFT;
119 | }
120 | }
121 |
122 | return Gravity.NO_GRAVITY;
123 | }
124 |
125 | public void setEventsListener(final FireLayout.EventsListener listener) {
126 | if (FireViewUtils.getValue(attributesMap.get("onClick"), false))
127 | view.setOnClickListener(new View.OnClickListener() {
128 | @Override
129 | public void onClick(View view) {
130 | listener.onFireLayoutChildClicked(view);
131 | }
132 | });
133 |
134 | if (FireViewUtils.getValue(attributesMap.get("onLongClick"), false))
135 | view.setOnLongClickListener(new View.OnLongClickListener() {
136 | @Override
137 | public boolean onLongClick(View view) {
138 | listener.onFireLayoutChildLongClicked(view);
139 | return true;
140 | }
141 | });
142 | }
143 |
144 | public abstract View generateView(Context mContext);
145 |
146 | public View getView() {
147 | return view;
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/firelayout/src/main/java/com/fs/firelayout/utils/FireViewGenerator.java:
--------------------------------------------------------------------------------
1 | package com.fs.firelayout.utils;
2 |
3 | import com.fs.firelayout.FireView;
4 |
5 | public enum FireViewGenerator {
6 | FireTextView("textview", com.fs.firelayout.views.FireTextView.class, false),
7 | FireEditText("edittext", com.fs.firelayout.views.FireEditText.class, false),
8 | FireButton("button", com.fs.firelayout.views.FireButton.class, false),
9 | FireImageView("imageview", com.fs.firelayout.views.FireImageView.class, false),
10 | FireLinearLayout("linearlayout", com.fs.firelayout.viewgroups.FireLinearLayout.class, true),
11 | FireRelativeLayout("relativelayout", com.fs.firelayout.viewgroups.FireRelativeLayout.class, true);
12 |
13 | String name;
14 | public Class extends FireView> viewClass;
15 | public boolean isViewGroup;
16 |
17 | FireViewGenerator(String name, Class extends FireView> viewClass, boolean isViewGroup) {
18 | this.name = name;
19 | this.viewClass = viewClass;
20 | this.isViewGroup = isViewGroup;
21 | }
22 |
23 | public static FireViewGenerator getFireView(String name) {
24 | for (FireViewGenerator fireViewGenerator : values()) {
25 | if (fireViewGenerator.name.equals(name.toLowerCase()))
26 | return fireViewGenerator;
27 | }
28 |
29 | return null;
30 | }
31 | }
--------------------------------------------------------------------------------
/firelayout/src/main/java/com/fs/firelayout/utils/FireViewUtils.java:
--------------------------------------------------------------------------------
1 | package com.fs.firelayout.utils;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.text.TextUtils;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.RelativeLayout;
9 |
10 | import java.util.HashMap;
11 |
12 | /**
13 | * Created by Francesco on 04/02/17.
14 | */
15 |
16 | public class FireViewUtils {
17 |
18 | public static Number getValue(Object value, int def) {
19 | if (value != null && value instanceof Number)
20 | return (Number) value;
21 |
22 | return def;
23 | }
24 |
25 | public static Boolean getValue(Object value, boolean def) {
26 | if (value != null && value instanceof Boolean)
27 | return (Boolean) value;
28 |
29 | return def;
30 | }
31 |
32 | public static String getValue(Object value, String def) {
33 | if (value != null && value instanceof String)
34 | return (String) value;
35 |
36 | return def;
37 | }
38 |
39 | public static int getResourceId(Context mContext, Object value, String def, String path) {
40 | Resources resources = mContext.getResources();
41 |
42 | String resource = getValue(value, def);
43 | int resId = -1;
44 |
45 | if (!TextUtils.isEmpty(resource))
46 | resId = resources.getIdentifier(resource, path, mContext.getPackageName());
47 |
48 | return resId;
49 | }
50 |
51 | public static void setLayoutParamsForParent(ViewGroup parent, View child, HashMap childAttributes) {
52 | ViewGroup.MarginLayoutParams oldLP = (ViewGroup.MarginLayoutParams) child.getLayoutParams();
53 |
54 | if (parent instanceof RelativeLayout) {
55 | RelativeLayout.LayoutParams newLP = new RelativeLayout.LayoutParams(oldLP.width, oldLP.height);
56 | newLP.setMargins(oldLP.leftMargin, oldLP.topMargin, oldLP.rightMargin, oldLP.bottomMargin);
57 | checkRelativeRule(newLP, childAttributes);
58 | child.setLayoutParams(newLP);
59 | }
60 | }
61 |
62 | private static void checkRelativeRule(RelativeLayout.LayoutParams layoutParams, HashMap attr) {
63 | if(getValue(attr.get("align_parent_left"), false))
64 | layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
65 | if(getValue(attr.get("align_parent_top"), false))
66 | layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
67 | if(getValue(attr.get("align_parent_right"), false))
68 | layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
69 | if(getValue(attr.get("align_parent_bottom"), false))
70 | layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
71 | if(getValue(attr.get("align_parent_start"), false))
72 | layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START);
73 | if(getValue(attr.get("align_parent_end"), false))
74 | layoutParams.addRule(RelativeLayout.ALIGN_PARENT_END);
75 | if(getValue(attr.get("center_in_parent"), false))
76 | layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
77 | if(getValue(attr.get("center_horizontal"), false))
78 | layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
79 | if(getValue(attr.get("center_vertical"), false))
80 | layoutParams.addRule(RelativeLayout.CENTER_VERTICAL);
81 |
82 | //TODO: MANAGE WITH ABOVE, BELOW, LEFT_OF AND RIGHT_OF. THE PROBLEM IS THE VIEW ID MANAGEMENT.
83 | //the following code doesn't work if applied on index < last_index
84 | /*String aboveTag = getValue(attr.get("above"), "");
85 | if(!TextUtils.isEmpty(aboveTag))
86 | {
87 | View view = parent.findViewWithTag(aboveTag);
88 | if(view != null)
89 | {
90 | layoutParams.addRule(RelativeLayout.ABOVE, view.getId());
91 | }
92 | }
93 |
94 | String belowTag = getValue(attr.get("below"), "");
95 | if(!TextUtils.isEmpty(aboveTag))
96 | {
97 | View view = parent.findViewWithTag(belowTag);
98 | if(view != null)
99 | {
100 | layoutParams.addRule(RelativeLayout.BELOW, view.getId());
101 | }
102 | }
103 |
104 | String leftTag = getValue(attr.get("left_of"), "");
105 | if(!TextUtils.isEmpty(aboveTag))
106 | {
107 | View view = parent.findViewWithTag(leftTag);
108 | if(view != null)
109 | {
110 | layoutParams.addRule(RelativeLayout.LEFT_OF, view.getId());
111 | }
112 | }
113 |
114 | String rightTag = getValue(attr.get("right_of"), "");
115 | if(!TextUtils.isEmpty(aboveTag))
116 | {
117 | View view = parent.findViewWithTag(rightTag);
118 | if(view != null)
119 | {
120 | layoutParams.addRule(RelativeLayout.RIGHT_OF, view.getId());
121 | }
122 | }*/
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/firelayout/src/main/java/com/fs/firelayout/viewgroups/FireLinearLayout.java:
--------------------------------------------------------------------------------
1 | package com.fs.firelayout.viewgroups;
2 |
3 | import android.content.Context;
4 | import android.text.TextUtils;
5 | import android.view.View;
6 | import android.widget.LinearLayout;
7 |
8 | import com.fs.firelayout.FireView;
9 |
10 | import java.util.HashMap;
11 |
12 | /**
13 | * Created by Francesco on 22/01/17.
14 | */
15 |
16 | public class FireLinearLayout extends FireView {
17 |
18 | public FireLinearLayout(Context context, HashMap map) {
19 | init(context, map);
20 | }
21 |
22 | @Override
23 | public View generateView(Context mContext) {
24 | LinearLayout linearLayout = new LinearLayout(mContext);
25 |
26 | linearLayout.setOrientation(getOrientation());
27 |
28 | linearLayout.setGravity(getGravity("gravity"));
29 |
30 | return linearLayout;
31 | }
32 |
33 | private int getOrientation()
34 | {
35 | Object orientation = attributesMap.get("orientation");
36 | if(orientation != null && orientation instanceof String && !TextUtils.isEmpty((String) orientation))
37 | {
38 | String o = (String) orientation;
39 |
40 | if(o.equals("vertical"))
41 | return LinearLayout.VERTICAL;
42 | else if(o.equals("horizontal"))
43 | return LinearLayout.HORIZONTAL;
44 | }
45 |
46 | return LinearLayout.VERTICAL;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/firelayout/src/main/java/com/fs/firelayout/viewgroups/FireRelativeLayout.java:
--------------------------------------------------------------------------------
1 | package com.fs.firelayout.viewgroups;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.widget.RelativeLayout;
6 |
7 | import com.fs.firelayout.FireView;
8 |
9 | import java.util.HashMap;
10 |
11 | /**
12 | * Created by Francesco on 22/01/17.
13 | */
14 |
15 | public class FireRelativeLayout extends FireView {
16 |
17 | public FireRelativeLayout(Context context, HashMap map) {
18 | init(context, map);
19 | }
20 |
21 | @Override
22 | public View generateView(Context mContext) {
23 | RelativeLayout relativeLayout = new RelativeLayout(mContext);
24 |
25 | relativeLayout.setGravity(getGravity("gravity"));
26 |
27 | return relativeLayout;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/firelayout/src/main/java/com/fs/firelayout/views/FireButton.java:
--------------------------------------------------------------------------------
1 | package com.fs.firelayout.views;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.text.TextUtils;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | import com.fs.firelayout.FireView;
10 | import com.fs.firelayout.utils.FireViewUtils;
11 |
12 | import java.util.HashMap;
13 |
14 | /**
15 | * Created by Francesco on 22/01/17.
16 | */
17 |
18 | public class FireButton extends FireView {
19 |
20 | public FireButton(Context context, HashMap map) {
21 | init(context, map);
22 | }
23 |
24 | @Override
25 | public View generateView(Context mContext) {
26 | Button button = new Button(mContext);
27 |
28 | button.setText(FireViewUtils.getValue(attributesMap.get("text"), ""));
29 |
30 | String textColor = FireViewUtils.getValue(attributesMap.get("textColor"), null);
31 | if (!TextUtils.isEmpty(textColor))
32 | button.setTextColor(Color.parseColor(textColor));
33 |
34 | float textSize = FireViewUtils.getValue(attributesMap.get("textSize"), -1).floatValue();
35 | if (textSize >= 0f)
36 | button.setTextSize(textSize);
37 |
38 | button.setGravity(getGravity("gravity"));
39 |
40 | return button;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/firelayout/src/main/java/com/fs/firelayout/views/FireEditText.java:
--------------------------------------------------------------------------------
1 | package com.fs.firelayout.views;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.text.TextUtils;
6 | import android.view.View;
7 | import android.widget.EditText;
8 |
9 | import com.fs.firelayout.FireView;
10 | import com.fs.firelayout.utils.FireViewUtils;
11 |
12 | import java.util.HashMap;
13 |
14 | /**
15 | * Created by Francesco on 22/01/17.
16 | */
17 |
18 | public class FireEditText extends FireView {
19 |
20 | public FireEditText(Context context, HashMap map) {
21 | init(context, map);
22 | }
23 |
24 | @Override
25 | public View generateView(Context mContext) {
26 | EditText editText = new EditText(mContext);
27 |
28 | editText.setText(FireViewUtils.getValue(attributesMap.get("text"), ""));
29 |
30 | editText.setHint(FireViewUtils.getValue(attributesMap.get("hint"), ""));
31 |
32 | String textColor = FireViewUtils.getValue(attributesMap.get("textColor"), null);
33 | if (!TextUtils.isEmpty(textColor))
34 | editText.setTextColor(Color.parseColor(textColor));
35 |
36 | float textSize = FireViewUtils.getValue(attributesMap.get("textSize"), -1).floatValue();
37 | if (textSize >= 0f)
38 | editText.setTextSize(textSize);
39 |
40 | editText.setGravity(getGravity("gravity"));
41 |
42 | return editText;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/firelayout/src/main/java/com/fs/firelayout/views/FireImageView.java:
--------------------------------------------------------------------------------
1 | package com.fs.firelayout.views;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Color;
6 | import android.text.TextUtils;
7 | import android.view.View;
8 | import android.widget.ImageView;
9 |
10 | import com.android.volley.Response;
11 | import com.android.volley.VolleyError;
12 | import com.android.volley.toolbox.ImageRequest;
13 | import com.android.volley.toolbox.Volley;
14 | import com.fs.firelayout.FireView;
15 | import com.fs.firelayout.utils.FireViewUtils;
16 |
17 | import java.util.HashMap;
18 |
19 | /**
20 | * Created by Francesco on 01/02/17.
21 | */
22 |
23 | public class FireImageView extends FireView {
24 |
25 | public FireImageView(Context context, HashMap map) {
26 | init(context, map);
27 | }
28 |
29 | @Override
30 | public View generateView(Context mContext) {
31 | ImageView imageView = new ImageView(mContext);
32 |
33 | loadImage(imageView, mContext);
34 |
35 | imageView.setAdjustViewBounds(FireViewUtils.getValue(attributesMap.get("adjustViewBounds"), false));
36 |
37 | String colorFilter = FireViewUtils.getValue(attributesMap.get("colorFilter"), "");
38 |
39 | if (!TextUtils.isEmpty(colorFilter))
40 | imageView.setColorFilter(Color.parseColor(colorFilter));
41 |
42 | return imageView;
43 | }
44 |
45 | private void loadImage(final ImageView imageView, Context mContext) {
46 | int srcId = FireViewUtils.getResourceId(mContext, attributesMap.get("src"), "", "drawable");
47 |
48 | if (srcId != -1) {
49 | imageView.setImageResource(srcId);
50 | imageView.setScaleType(getScaleType());
51 | imageView.setMaxWidth(FireViewUtils.getValue(attributesMap.get("maxWidth"), 0).intValue());
52 | imageView.setMaxHeight(FireViewUtils.getValue(attributesMap.get("maxHeight"), 0).intValue());
53 | } else {
54 | String srcUrl = FireViewUtils.getValue(attributesMap.get("srcUrl"), "");
55 |
56 | if (!TextUtils.isEmpty(srcUrl)) {
57 | final int srcErrorId = FireViewUtils.getResourceId(mContext, attributesMap.get("srcError"), "", "drawable");
58 |
59 | ImageRequest imageRequest = new ImageRequest(srcUrl,
60 | new Response.Listener() {
61 | @Override
62 | public void onResponse(Bitmap bitmap) {
63 | imageView.setImageBitmap(bitmap);
64 | }
65 | }, FireViewUtils.getValue(attributesMap.get("maxWidth"), 0).intValue(), FireViewUtils.getValue(attributesMap.get("maxHeight"), 0).intValue(), getScaleType(), null,
66 | new Response.ErrorListener() {
67 | public void onErrorResponse(VolleyError error) {
68 | if (srcErrorId != -1)
69 | imageView.setImageResource(srcErrorId);
70 | }
71 | });
72 |
73 | Volley.newRequestQueue(mContext.getApplicationContext()).add(imageRequest);
74 | }
75 | }
76 | }
77 |
78 | private ImageView.ScaleType getScaleType() {
79 | String scale = FireViewUtils.getValue(attributesMap.get("scaleType"), "CENTER_INSIDE");
80 |
81 | ImageView.ScaleType scaleType = ImageView.ScaleType.valueOf(scale.toUpperCase());
82 |
83 | return scaleType;
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/firelayout/src/main/java/com/fs/firelayout/views/FireTextView.java:
--------------------------------------------------------------------------------
1 | package com.fs.firelayout.views;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.text.TextUtils;
6 | import android.view.View;
7 | import android.widget.TextView;
8 |
9 | import com.fs.firelayout.FireView;
10 | import com.fs.firelayout.utils.FireViewUtils;
11 |
12 | import java.util.HashMap;
13 |
14 | /**
15 | * Created by Francesco on 22/01/17.
16 | */
17 |
18 | public class FireTextView extends FireView {
19 |
20 | public FireTextView(Context context, HashMap map) {
21 | init(context, map);
22 | }
23 |
24 | @Override
25 | public View generateView(Context mContext) {
26 | TextView textView = new TextView(mContext);
27 |
28 | textView.setText(FireViewUtils.getValue(attributesMap.get("text"), ""));
29 |
30 | String textColor = FireViewUtils.getValue(attributesMap.get("textColor"), null);
31 | if (!TextUtils.isEmpty(textColor))
32 | textView.setTextColor(Color.parseColor(textColor));
33 |
34 | float textSize = FireViewUtils.getValue(attributesMap.get("textSize"), -1).floatValue();
35 | if (textSize >= 0f)
36 | textView.setTextSize(textSize);
37 |
38 | textView.setGravity(getGravity("gravity"));
39 |
40 | return textView;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/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 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FStranieri/FireLayout/b510e7eb030dbe71ce42f1a65f6a4b98d791f79d/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.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # 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 |
--------------------------------------------------------------------------------
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "24.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.fs.firelayout.sample"
9 | minSdkVersion 15
10 | targetSdkVersion 25
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | compile fileTree(include: ['*.jar'], dir: 'libs')
27 | compile project(":firelayout")
28 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
29 | exclude group: 'com.android.support', module: 'support-annotations'
30 | })
31 | compile 'com.android.support:appcompat-v7:25.0.1'
32 | testCompile 'junit:junit:4.12'
33 | }
34 |
--------------------------------------------------------------------------------
/sample/firelayoutSampleConf.json:
--------------------------------------------------------------------------------
1 | {
2 | "fire1": {
3 | "relativelayout": {
4 | "layout_width": "match_parent",
5 | "layout_height": "match_parent",
6 | "padding": 5,
7 | "children": {
8 | "linearlayout": {
9 | "layout_width": "match_parent",
10 | "layout_height": "wrap_content",
11 | "orientation": "vertical",
12 | "center_in_parent": true,
13 | "gravity": "center",
14 | "children": {
15 | "imageview": {
16 | "tag": "img1",
17 | "layout_width": "wrap_content",
18 | "layout_height": "wrap_content",
19 | "srcUrl": "https://cdn4.iconfinder.com/data/icons/google-i-o-2016/512/google_firebase-512.png",
20 | "srcError": "ic_action_name",
21 | "onClick": true
22 | },
23 | "textview": {
24 | "layout_width": "match_parent",
25 | "layout_height": "wrap_content",
26 | "text": "Hi, FireLayout!",
27 | "textColor": "#FFFFFF",
28 | "textSize": 20,
29 | "background": "#404040",
30 | "gravity": "center",
31 | "padding": 5,
32 | "onClick": true
33 | },
34 | "button": {
35 | "tag": "bt1",
36 | "layout_width": "wrap_content",
37 | "layout_height": "wrap_content",
38 | "text": "OK",
39 | "textColor": "#404040",
40 | "background": "#FFFFFF",
41 | "gravity": "center",
42 | "padding": 5,
43 | "margin_top": 10,
44 | "onClick": true,
45 | "onLongClick": true
46 | }
47 | }
48 | }
49 | }
50 | }
51 | }
52 | }
--------------------------------------------------------------------------------
/sample/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/Francesco/Library/Android/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 |
--------------------------------------------------------------------------------
/sample/src/androidTest/java/com/fs/firelayout/sample/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.fs.firelayout;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.fs.firelayout", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/fs/firelayout/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.fs.firelayout.sample;
2 |
3 | import android.support.design.widget.Snackbar;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.view.View;
7 |
8 | import com.fs.firelayout.FireLayout;
9 | import com.google.firebase.database.FirebaseDatabase;
10 |
11 | public class MainActivity extends AppCompatActivity implements FireLayout.EventsListener {
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.activity_main);
17 |
18 | FireLayout fireLayout = (FireLayout) findViewById(R.id.fire1);
19 |
20 | fireLayout.setEventsListener(this);
21 | fireLayout.init(FirebaseDatabase.getInstance());
22 | }
23 |
24 | @Override
25 | public void onFireLayoutChildClicked(View view) {
26 | //if you add a tag in your view, you can do some logic to identify the view
27 | Snackbar
28 | .make(view, view.getTag() != null ? view.getTag() + " - Clicked!" : "Clicked!", Snackbar.LENGTH_SHORT)
29 | .show();
30 | }
31 |
32 | @Override
33 | public void onFireLayoutChildLongClicked(View view) {
34 | //if you add a tag in your view, you can do some logic to identify the view
35 | Snackbar
36 | .make(view, view.getTag() != null ? view.getTag() + " - LongClicked!" : "LongClicked!", Snackbar.LENGTH_SHORT)
37 | .show();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-hdpi/ic_action_name.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FStranieri/FireLayout/b510e7eb030dbe71ce42f1a65f6a4b98d791f79d/sample/src/main/res/drawable-hdpi/ic_action_name.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-mdpi/ic_action_name.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FStranieri/FireLayout/b510e7eb030dbe71ce42f1a65f6a4b98d791f79d/sample/src/main/res/drawable-mdpi/ic_action_name.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xhdpi/ic_action_name.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FStranieri/FireLayout/b510e7eb030dbe71ce42f1a65f6a4b98d791f79d/sample/src/main/res/drawable-xhdpi/ic_action_name.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/ic_action_name.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FStranieri/FireLayout/b510e7eb030dbe71ce42f1a65f6a4b98d791f79d/sample/src/main/res/drawable-xxhdpi/ic_action_name.png
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FStranieri/FireLayout/b510e7eb030dbe71ce42f1a65f6a4b98d791f79d/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FStranieri/FireLayout/b510e7eb030dbe71ce42f1a65f6a4b98d791f79d/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FStranieri/FireLayout/b510e7eb030dbe71ce42f1a65f6a4b98d791f79d/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FStranieri/FireLayout/b510e7eb030dbe71ce42f1a65f6a4b98d791f79d/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FStranieri/FireLayout/b510e7eb030dbe71ce42f1a65f6a4b98d791f79d/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | FireLayout Sample
3 |
4 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/sample/src/test/java/com/fs/firelayout/sample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.fs.firelayout;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':firelayout', ':sample'
2 |
--------------------------------------------------------------------------------