FireLayout


Source link: https://github.com/FStranieri/FireLayout

FireLayout (Android)

Description

FireLayout is a CoordinatorLayout linked to its refence on your Firebase Real-Time Database. You can generate your own layout through firebase console.

Importing with Gradle

compile 'com.fs.firelayout:firelayout:0.2.5' 

Importing with Maven

<dependency>
<groupId>com.fs.firelayout</groupId>
<artifactId>firelayout</artifactId>
<version>0.2.5</version>
<type>pom</type> </dependency> 

Setup

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.

How to

Create an instance of FireLayout in your layout file or by java code.

Example:

<com.fs.firelayout.FireLayout

android:id="@+id/fire1"

android:layout_width="match_parent"

android:layout_height="match_parent" />
  

Note: 'android:id' is mandatory! It's the reference in your firebase database.

Now you have to instantiate the FireLayout:

... FirebaseDatabase database = FirebaseDatabase.getInstance();
 FireLayout fireLayout = (FireLayout) findViewById(R.id.fire1);
  //if you want to listen events fireLayout.setEventsListener(new FireLayout.EventsListener() {

 @Override

 public void onFireLayoutChildClicked(View view) {

  //if you add a tag in your view, you can do some logic to identify the view

 
}

  @Override

 public void onFireLayoutChildLongClicked(View view) {

  //if you add a tag in your view, you can do some logic to identify the view

 
}

}
);
  fireLayout.init(database);
 ...

Now you're ready to build your own layout!

Example (in sample app folder 'firelayoutSampleConf.json'):

{

"fire1": {

  "relativelayout": {

 "layout_width": "match_parent",

 "layout_height": "match_parent",

 "padding": 5,

 "children": {

"linearlayout": {

  "layout_width": "match_parent",

  "layout_height": "wrap_content",

  "orientation": "vertical",

  "center_in_parent": true,

  "gravity": "center",

  "children": {

 "imageview": {

"tag": "img1",

"layout_width": "wrap_content",

"layout_height": "wrap_content",

"srcUrl": "https://cdn4.iconfinder.com/data/icons/google-i-o-2016/512/google_firebase-512.png",

"srcError": "ic_action_name",

"onClick": true

 
}
,

 "textview": {

"layout_width": "match_parent",

"layout_height": "wrap_content",

"text": "Hi, FireLayout!",

"textColor": "#FFFFFF",

"textSize": 20,

"background": "#404040",

"gravity": "center",

"padding": 5,

"onClick": true

 
}
,

 "button": {

"tag": "bt1",

"layout_width": "wrap_content",

"layout_height": "wrap_content",

"text": "OK",

"textColor": "#404040",

"background": "#FFFFFF",

"gravity": "center",

"padding": 5,

"margin_top": 10,

"onClick": true,

"onLongClick": true

 
}

  
}

}

 
}

  
}

}
 
}

Import your json in your Firebase database and you're done!

Views

This library is in development and I'm adding new attributes and views. I'll update the following list each update:

Views :

  • All

tag = "tag" (use it as identifier)

layout_width = integer / "wrap_content" / "match_parent"

layout_height = integer / "wrap_content" / "match_parent"

background = "exadecimal_code", see example

enable = true/false, default true

visibility = "gone" / "invisible", default visible

padding = integer (if exists, other padding values won't be effective)

padding_top = integer

padding_left = integer

padding_right = integer

padding_bottom = integer

margin = integer (if exists, other margin values won't be effective)

margin_top = integer

margin_left = integer

margin_right = integer

margin_bottom = integer

onClick = true/false, default false

onLongClick = true/false, default false

ViewGroups:

  • All:

    children = { "childviewname" : { } }

  • linearlayout (LinearLayout)

    orientation = "vertical" / "horizontal"

    gravity = "center" / "center_horizontal" / "center_vertical" / "bottom" / "top" / "left" / "right"

  • relativelayout (RelativeLayout)

    gravity = "center" / "center_horizontal" / "center_vertical" / "bottom" / "top" / "left" / "right"

    RelativeLayout has optional rules for its children, so in your child object you can add following (see json sample):

    align_parent_left = true / false, default false

    align_parent_top = true / false, default false

    align_parent_right = true / false, default false

    align_parent_bottom = true / false, default false

    align_parent_start = true / false, default false

    align_parent_end = true / false, default false

    center_in_parent = true / false, default false

    center_horizontal = true / false, default false

    center_vertical = true / false, default false

Children Views :

  • textview (TextView)

    text = "text"

    textColor = "exadecimal_code", see example

    textSize = integer / double

    gravity = "center" / "center_horizontal" / "center_vertical" / "bottom" / "top" / "left" / "right"

  • edittext (EditText)

    text = "text"

    hint = "hint"

    textColor = "exadecimal_code", see example

    textSize = integer / double

    gravity = "center" / "center_horizontal" / "center_vertical" / "bottom" / "top" / "left" / "right"

  • button (Button)

    text = "text"

    textColor = "exadecimal_code", see example

    textSize = integer / double

    gravity = "center" / "center_horizontal" / "center_vertical" / "bottom" / "top" / "left" / "right"

  • imageview (ImageView)

    src = "name of drawable, in drawable folders"

    srcUrl = "url to image", not effective if src is set

    srcError = "name of drawable, in drawable folders", this is your image when srcUrl fails and It's not effective if src is set

    adjustViewBounds = boolean, default false

    scaleType = "scaletype", accepted values : "CENTER", "CENTER_CROP", "CENTER_INSIDE", "FIT_CENTER", "FIT_END", "FIT_START", "FIT_XY", "MATRIX". Default is CENTER_INSIDE.

    colorFilter = "exadecimal_code", see example

    maxHeight = number

    maxWidth = number

LICENSE

Copyright 2016 Francesco Stranieri

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Resources

Generates a Java Object for your xml layout to reduce inflate time to zero.

The Android Support Library for NFC.

Simplest way to get all images based on date, name, id, and other customizations.

A Magic library to take photos and select pictures in Android. In a simple way and if you need it also save the pictures in device.

A simple wrapper around most Firebase functions with RxJava.

Fluent mockito.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes