Giter VIP home page Giter VIP logo

dynamicob's Introduction

License API Android Arsenal

Dynamico

Android library for inflating dynamic layouts in runtime based on JSON configuration fetched from server. Useful in situations when layouts need to change without updating the app.

Advanced features

  • Targeting specific devices by brand, model and Android API version
  • Layout changes based on configuration fields

Installing

  1. Add repository in root build.gradle
allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}
  1. Add the dependency
dependencies {
    compile 'com.github.jelic98:dynamico:1.2.0'
}

Usage

  1. Create JSON layout and upload it somewhere
{
  "views":[  
    {  
      "class":"android.widget.ImageView",
      "attributes":{  
        "layout_width":"wrap_content",
        "layout_height":"wrap_content",
        "src":"https://lazarjelic.com/ecloga/projects/dynamico/logo.png",
        "cache":true
      }
    },
    {  
      "class":"android.widget.TextView",
      "attributes":{  
        "text":"Yo!",
        "textColor":"#FF69B4"
      }
    }
  ]
}
  1. Create XML wrapper layout that will contain loaded views
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="match_parent"
	android:layout_height="match_parent"
	android:orientation="vertical"
	android:id="@+id/mainLayout">
		
	<!-- Dynamic content will be added here -->
</LinearLayout>
  1. Initialize Dynamico by passing it:
  • URL = Link to JSON layout directory
  • name = Name of JSON layout file
  • layout = Wrapper layout that will contain loaded views
new Dynamico("https://lazarjelic.com/ecloga/projects/dynamico",
    "activity_main",
    findViewById(R.id.mainLayout))
    .initialize();

Manual

For advanced usage, take a look at this awesome manual.

Additional features

  • Event listener
setListener(new LayoutStateListener() {
	@Override
	public void onSuccess(String message) {
		// everything is okay
	}
	
	@Override
	public void onError(String message) {
		// notify user
	}
})
  • Loading from cache (skip layout fetching from server)
setOptions(CACHE_ONLY)
  • Non-stop layout fetching
setOptions(NON_STOP) // use with setAsyncPause(long millis)

Documentation

public Dynamico(String url, String name, ViewGroup layout) throws DynamicoException

One and only constructor

  • Parameters:
    • url — URL of directory where JSON layout file is located (for example, "https://lazarjelic.com/ecloga/projects/dynamico")
    • name — JSON layout file name with or without extension (for example, "activity_main")
    • layout — wrapper layout that will contain inflated layout from JSON file (for example, findViewById(R.id.mainLayout))
  • Exceptions: DynamicoException — if any of passed parameters is null
public Dynamico setListener(DynamicoListener listener)

Attaches event listener to Dynamico object

  • Parameters: listener — listener for success and error events caused by network, storage, etc.
  • Returns: Dynamico object ready for initialization
public Dynamico setOptions(DynamicoOptions.Option ... options)

Attaches options to Dynamico object

  • Parameters: options — options for Dynamico (for example, ONLY_CACHE)
  • Returns: Dynamico object ready for initialization
public void initialize()

Starts layout fetching from cache/server depending on provided options

TODO

  • Support vector drawables
  • Support more views

dynamicob's People

Contributors

jelic98 avatar pbertsch avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.