[] Define and render UI specs on top of your Android UI

Related tags

UI/UX dspec
Overview

dspec

A simple way to define and render UI specs on top of your Android UI.

Usage

Enclose the target UI with a DesignSpecFrameLayout, usually the root of your view hierarchy. Get the associated DesignSpec instance with getDesignSpec and then you can:

  • Toggle baseline grid visibility with setBaselineGridVisible(boolean).
  • Change baseline grid cell width with setBaselineGridCellSize(int).
  • Change baseline grid color with setBaselineGridColor(int).
  • Toggle keylines visibility with setKeylinesVisible(boolean).
  • Change keylines color with setKeylinesColor(int).
  • Add keylines with addKeyline(int, From).
  • Toggle spacing markers visibility with setSpacingsVisible(boolean).
  • Change spacing markers color with setSpacingsColor(int).
  • Add spacing marker with addSpacing(int, int, From).

You can also specify the design spec in a raw JSON resource like:

{
    "baselineGridVisible": true,
    "baselineGridCellSize": 8,
    "keylines": [
        { "offset": 16,
          "from": "LEFT" },
        { "offset": 72,
          "from": "LEFT" },
        { "offset": 16,
          "from": "RIGHT" }
    ],
    "spacings": [
        { "offset": 0,
          "size": 16,
          "from": "LEFT" },
        { "offset": 56,
          "size": 16,
          "from": "LEFT" },
        { "offset": 0,
          "size": 16,
          "from": "RIGHT" }
    ]
}

Because DesignSpec is a Drawable, you can simply add it to a ViewOverlay if you're running your app on API level >= 18:

DesignSpec designSpec = DesignSpec.fromResource(someView, R.raw.some_spec);
someView.getOverlay().add(designSpec);

Download

Download the latest JAR or grab via Gradle:

compile 'org.lucasr.dspec:dspec:0.1.1'

or Maven:

<dependency>
  <groupId>org.lucasr.dspec</groupId>
  <artifactId>dspec</artifactId>
  <version>0.1.1</version>
</dependency>

License

Copyright 2014 Lucas Rocha

Licensed under the Apache License, Version 2.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.
Comments
  • Add option to split the baseline grid.

    Add option to split the baseline grid.

    It's not uncommon for a design to call for bottom-anchored content, such as buttons, snackbars, drawers, etc. Such content should be grid-aligned internally, but its grid should originate at the bottom of the screen and may not align with the top-anchored grid.

    This change adds an option to split the grid at a given point on the screen. There will then be two grids, one originating at TOP and one at BOTTOM. If the grids do not align, a "gutter" will be left between them to indicate the odd space. The gutter will always be narrower than the baseline grid size.

    dspec_split_grid-2

    opened by loganj 5
  • Refactor DesignSpecFrameLayout to draw on top of content.

    Refactor DesignSpecFrameLayout to draw on top of content.

    The problem with using onDraw() in a ViewGroup is that this method actually draws _underneath_ the child view contents. This is an acceptable scenario for a basic layout with lots of transparency, but as soon as your view hierarchy starts including any significant amount of background images or colors, the grid becomes completely invisible.

    To properly draw _over_ the content in a ViewGroup, override dispatchDraw() and call your custom code after super. A nice side-effect of this is that you no longer has to disable the drawing optimization in ViewGroup either.

    opened by devunwired 3
  • DesignSpec as Drawable.

    DesignSpec as Drawable.

    What about Drawable adapter to design spec? I see following use case for it.

    public class DesignSpecDrawable extends Drawable {
        private final DesignSpec mDesignSpec;
    
        public DesignSpecDrawable(DesignSpec designSpec) {
            mDesignSpec = designSpec;
        }
    
        @Override
        public void draw(Canvas canvas) {
            if (mDesignSpec != null) {
                mDesignSpec.draw(canvas);
            }
        }
    
        /* ... */
    }
    
    setContentView(R.layout.main_activity);
    /* Resolve views here */
    
    View decorView = getWindow().getDecorView();
    mDesignSpec = DesignSpec.fromResource(decorView, R.raw.main_activity_spec);
    DesignSpecDrawable drawable = new DesignSpecDrawable(mDesignSpec);
    decorView.getOverlay().add(drawable); 
    

    The main advantage that is dspec now controlled from the code. It means we can now easily make it conditional, like:

    if (BuildConfig.USE_DSPEC) {
      // ...
    }
    

    So it can be stripped from production builds with ease.

    However, there is one problem ViewOverlays are only available since API 18 (JB 4.3). Although, we can still use it below this API level by setting it as background, or ImageView or so on, which is not so convient.

    opened by pepyakin 2
  • Support for mathematical calculations

    Support for mathematical calculations

    Adding support for basic calculations in the size and offset fields would improve readablilty:

    {
        "keylines": [
            {
                "offset": 56,
                "from": "TOP"
            }, {
                "offset": 56 + 24,
                "from": "TOP"
            }, {
                "offset": 56 + (2 * 24),
                "from": "TOP"
            }
        ]
    }
    
    opened by martynhaigh 0
  • Support for percentage widths

    Support for percentage widths

    It's be great to have percentage values supported in the offset and size fields.

    For example:

    {
    "keylines": [
        {
            "offset": 50%,
            "from": "LEFT"
        }, {
            "offset": 50%,
            "from": "TOP"
        },
    }
    
    opened by martynhaigh 0
Owner
Lucas Rocha
Mobile UI platform at Facebook. Formerly at Mozilla, GNOME, litl, and Nokia.
Lucas Rocha
Janishar Ali 2.1k Jan 1, 2023
Owasp-top-five - An intro into writing code for greater Android Security

Don’t get stung by OWASP An intro into writing code for greater Android Security

Ed George 5 Feb 13, 2022
TopSheet - a "top" version of BottomSheet

TopSheet - a "top" version of BottomSheet TopSheetBehaviour View sheet = findViewById(R.id.top_sheet); TopSheetBehavior.from(sheet).setState(TopSheetB

Andrea Maglie 82 Jun 24, 2022
Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your development.

Bubbles for Android Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your

Txus Ballesteros 1.5k Jan 2, 2023
Make your native android Toasts Fancy. A library that takes the standard Android toast to the next level with a variety of styling options. Style your toast from code.

FancyToast-Android Prerequisites Add this in your root build.gradle file (not your module build.gradle file): allprojects { repositories { ... ma

Shashank Singhal 1.2k Dec 26, 2022
Make your native android Dialog Fancy. A library that takes the standard Android Dialog to the next level with a variety of styling options. Style your dialog from code.

FancyAlertDialog-Android Prerequisites Add this in your root build.gradle file (not your module build.gradle file): allprojects { repositories { ..

Shashank Singhal 350 Dec 9, 2022
This library provides a simple way to add a draggable sliding up panel (popularized by Google Music and Google Maps) to your Android application. Brought to you by Umano.

Note: we are not actively responding to issues right now. If you find a bug, please submit a PR. Android Sliding Up Panel This library provides a simp

Umano: News Read To You 9.4k Dec 31, 2022
GreenDroid is a development library for the Android platform. It makes UI developments easier and consistent through your applications.

#GreenDroid Foreword : This project, initially initiated by me, Cyril Mottier, is not maintained anymore and can be considered as deprecated. As a con

Cyril Mottier 2.6k Jan 4, 2023
[Archived] Highlight the best bits of your app to users quickly, simply, and cool...ly

ShowcaseView The ShowcaseView (SCV) library is designed to highlight and showcase specific parts of apps to the user with a distinctive and attractive

Alex Curran 5.6k Dec 16, 2022
A simple library to let you sign (or draw lines) smoothly with your finger into a view and save it.

FingerSignView Introduction FingerSignView is a simple library that lets you finger, or draw lines, smoothly with your finger into a View and save it

Agnaldo Pereira 25 Nov 20, 2022
A Jetpack Compose library with blur, pixelate, and other effects to keep your designer happy. Inspired by iOS UIVisualEffectView.

A Jetpack Compose library with blur, pixelate, and other effects to keep your designer happy. Inspired by iOS UIVisualEffectView.

清茶 67 Dec 30, 2022
Useful library to use custom fonts in your android app

EasyFonts A simple and useful android library to use custom fonts in android apps without adding fonts into asset/resource folder.Also by using this l

Vijay Vankhede 419 Sep 9, 2022
Make a cool intro for your Android app.

AppIntro AppIntro is an Android Library that helps you build a cool carousel intro for your App. AppIntro has support for requesting permissions and h

AppIntro Team 10.3k Dec 30, 2022
:bread: Make your native android Toasts Tasty

TastyToast Make your native android toast look beautiful. Preview About Refer Here Wiki Grab the above demo app from here : Dependency Add dependency

Rahul Yadav 2k Dec 29, 2022
StandOut lets you easily create floating windows in your Android app.

Coming Soon Meanwhile, checkout the demo video at http://www.youtube.com/watch?v=S3vHjxonOeg Join the conversation at http://forum.xda-developers.com/

Mark Wei 1.2k Dec 12, 2022
A simple library to add Emoji support to your Android Application

Emoji A library to add Emoji support to your Android app. Emojis can be picked in a PopupWindow. In order to edit and display text with Emojis this li

Niklas Baudy 1.4k Jan 4, 2023
Add some depth to your Android scrolling.

Parallax Pager Add some depth to your Android scrolling using the parallax effect! Installation Step 1. Add the JitPack repository to your build file

Prolific Interactive 782 Dec 29, 2022
Android Library to display your changelog

ChangeLog Library ChangeLog Library provides an easy way to display a change log in your Android app. Travis master: Travis dev: Examples Sample appli

Gabriele Mariotti 861 Nov 11, 2022
A drawing view for your android application.

Android Draw A drawing view for your android application Download For information : checkout Sample App Code in repository. Dependency Step 1. Add the

Divyanshu Bhargava 409 Dec 30, 2022