Custom UI control for android which is showing data as a segments and a value inside them.

Overview

Segmented Bar View for Android

Custom UI control for android which is showing data as a segments and a value inside them.

Screenshots

Imgur

Install

From repositories

Add jcenter to project repositories

repositories {
    jcenter()
}

Add compile line to project dependencies

compile 'mobi.gspd:segmentedbarview:1.1.6@aar'

Local aar

Download

Put aar into app/libs folder. Add flatDir in build.gradle

repositories {
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
}

And add dependency

compile 'mobi.gspd:segmentedbarview:1.1.6@aar'

Usage

Builder

SegmentedBarView barView = SegmentedBarView.builder(this)
                           .segments(segments)
                           .value(5.25f)
                           .unit("ml<sup>2</sup>")
                           .showDescriptionText(true)
                           .sideStyle(SegmentedBarViewSideStyle.ANGLE)
                           .build();

Constructor and setters

SegmentedBarView barView = new SegmentedBarView(this);
barView.setValueWithUnit(4.96f, "10<sup>12</sup>/l"); /* You can use Html tags here in unit to support superscript and subscript */
barView.setSegments(segments);

Within xml layout

<mobi.gspd.segmentedbarview.SegmentedBarView
        android:id="@+id/bar_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="20dp"
        app:sbv_empty_segment_text="No segments"
        app:sbv_segment_gap_width="10dp"
        app:sbv_segment_text_size="20sp"
        app:sbv_show_description_text="true"
        app:sbv_side_style="angle"
        app:sbv_side_text_style="twoSided"
        app:sbv_value_sign_height="30dp"
        app:sbv_value_sign_round="8dp"
        app:sbv_value_sign_width="30dp" 
/>

Create segments

In any case you should create segments list to put in view.

List<Segment> segments = new ArrayList<>();
Segment segment = new Segment(0, 4.5f, "Low", Color.parseColor("#EF3D2F"));
segments.add(segment);
Segment segment2 = new Segment(4.5f, 6.5f, "Optimal", Color.parseColor("#8CC63E"));
segments.add(segment2);
Segment segment3 = new Segment(6.5f, 20f, "High", Color.parseColor("#EF3D2F"));
segments.add(segment3);

Each segment contains min and max value, color, description text (optional), custom text (optional). Value sign position is calculated automatically in these intervals.

Also there can be segments with no min and max. Then you should set valueSegment field of SegmentedBarView, it's just an index of segment to show value sign over.

Customization

Xml attributes

Here is list of xml attributes and their defaults.

  • sbv_show_description_text - boolean
    • false (default)
  • sbv_show_segment_text - boolean
    • true (default)
  • sbv_value_sign_background - color
    • #7492E2 (default)
  • sbv_empty_segment_background - color
    • #858585 (default)
  • sbv_description_text_size - dimension
    • 14sp (default)
  • sbv_value_text_size - dimension
    • 14sp (default)
  • sbv_segment_text_size - dimension
    • 14sp (default)
  • sbv_bar_height - dimension
    • 24dp (default)
  • sbv_value_sign_height - dimension
    • 32dp (default)
  • sbv_value_sign_width - dimension
    • 72dp (default)
  • sbv_arrow_height - dimension
    • 5dp (default)
  • sbv_arrow_width - dimension
    • 10dp (default)
  • sbv_description_box_height - dimension
    • 24dp (default)
  • sbv_value_sign_round - dimension
    • 4dp (default)
  • sbv_side_style - enum
    • normal (default)
    • rounded
    • angle
  • sbv_side_text_style - enum
    • oneSided (default)
    • twoSided

All of these also can be set via setters of SegmentedBarView class.

License

The MIT License (MIT)

Copyright (c) 2015 gspd.mobi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

This code was produced for Clinishare Ltd. This code is published as open-source with the permission of Clinishare Ltd. www.clinishare.net

You might also like...
TrackerControl: monitor and control trackers and ads.
TrackerControl: monitor and control trackers and ads.

About TrackerControl Download directly here, from F-Droid, or a feature-reduced version from Google Play. If you have missing features or bugs, join t

πŸš€ React Native Segmented Control, Pure Javascript for iOS and Android
πŸš€ React Native Segmented Control, Pure Javascript for iOS and Android

Installation Add the dependency: npm i react-native-segmented-control-2 Peer Dependencies Zero Dependency πŸ₯³ Usage Import import SegmentedControl from

Android News App built in kotlin with implementation of MVVM architecture, android navigation components and retrofit. Displays news to users allowing them to share and save news.
Android News App built in kotlin with implementation of MVVM architecture, android navigation components and retrofit. Displays news to users allowing them to share and save news.

News-App Android news app built in kotlin that fetches news data from news api with Retrofit and displays news to users. This App follow MVVM architec

Post It is the android App for uploading posts and liking them using Firebase and FireStore.

Post-it Post It is the android App for uploading posts and liking them using Firebase and FireStore. This app also uses DAO, RecycleView, Coroutines a

Find your ideal fitness partners according to your preferences and interact with them whenever you want! All this with no hassle, because there's FitMate! Take timed challenges updated daily, read blogs related to health, and be a part of numerous communities too! During covid times, partner with your FitMate to achieve your fitness goals at home. Money Manager app that helps you to add your daily small incomes and expenses and track them easily.
Money Manager app that helps you to add your daily small incomes and expenses and track them easily.

Simple Money Manager This app is a simple money manager app which helps you to add your daily small incomes and expenses and track them easily. Screen

Application that allows to search some products and display them in a list, also allows to add some product to the shopping cart and remove it
Application that allows to search some products and display them in a list, also allows to add some product to the shopping cart and remove it

Application that allows to search some products and display them in a list, also allows to add some product to the shopping cart and remove it

An android & arduino project. The android app is used to control motors via Arduino.
An android & arduino project. The android app is used to control motors via Arduino.

Boccia ramp project An android & arduino project. The android app is used to control motors via Arduino. Description This project is made in the conte

Ground Control Station for Android Devices

Tower Tower is a Ground Control Station (GCS) Android app built atop DroneKit-Android, for UAVs running Ardupilot software. Usage Guide The wiki has s

Comments
  • Segmented Padding in the end

    Segmented Padding in the end

    I would like to ask about some sort of unexpected behavior. The library appears to have some invisible padding in the end, so when I set it let's say at 200dp, it 'builds' until 150dp and the other 50dp is invisible/transparent, so the alignment with other elements is impossible. Do you have any idea of what should I do? In order to validate it, I used Android's see bounds from settings-programming section.

    Thanks a lot for your time and for delivering your library, it is pretty good!!

    opened by fpasxos 0
  • Different width of segments

    Different width of segments

    Hello everyone, Is there a possible way to customize the width of each particular segment? For example, I have a bar that has 3 segments and I would like the left segment to have, let's say 5dp, the middle one 12 and the right one 10. Is there a feature that implements this functionallity or if not, is there a possibillity to integrate it (The 'solution' of adding 3 seperate bars, does not fit me :/ ) ? Thanks in advance!! :)

    opened by fpasxos 1
Owner
GSPD
We Create Value for Startups, SMEs, and Investors
GSPD
KVMapper: A Key-Value Mapper app for MacOS, created with Kotlin and Compose Desktop

KVMapper is an application to convert key-value pairs from one format to another. About This app was purely written in Kotlin and compiled fo

Sebastian Neubauer 8 Nov 15, 2022
Helps to find your surrounding's light value (for android only) using device light sensor

react-native-ambient-light-sensor Helps to find your surrounding's light value (in lux unit) (for android only) using device light sensor Installation

Shayan Chatterjee 4 Aug 26, 2022
Example of Android project showing integration with Kotlin and Dagger 2

kotlin-dagger-example This project demonstrate how to setup an Android Project with Kotlin and Dagger 2. It's based on Dagger 2 example ##Known issues

Damian Petla 533 Nov 11, 2022
Android application showing list of Countries with National capital and flag.

Countries Android application showing list of Countries with National capital and flag. Implemented using Android MVVM architecture and used RxJava, D

Kartikay singh 1 Nov 28, 2021
SNS app showing nearby parks and forests

?? LittleForest Little ForestλŠ” 곡원과 μžμ—°νœ΄μ–‘λ¦Όμ„ μ†Œκ°œν•˜κ³ , 사진을 κ³΅μœ ν•˜λŠ” μ•ˆλ“œλ‘œμ΄λ“œ SNS μ–΄ν”Œλ¦¬μΌ€μ΄μ…˜μž…λ‹ˆλ‹€. 우리

hyobeom han 0 Dec 26, 2021
A beautiful app showing the use of a single recyclerview to display multiple views with motion layout and clean architecture

This app shows how to use a single recyclerview to build a beautiful multiple view layout (See image below) using clean architectural pattern

Ibrajix 62 Dec 26, 2022
A full-stack application showing the power πŸ’ͺ of KOTLIN. Entire android app + backend Apis written in Kotlin πŸ”₯

Gamebaaz ?? A full-stack application showing the power ?? of KOTLIN. Entire android app + backend Apis written in Kotlin ?? Android Backend Jetpack Co

Sarnava Konar 85 Nov 17, 2022
Samples showing best practices for MIDI on Android.

MIDI Samples This repository contains a set of individual Android Studio projects to help you write apps using MIDI APIs. Android MIDI 2.0 API samples

Android 23 Dec 19, 2022
A simple sample showing the different types of notifications on Andoid

Notification example Simple notification. Expandable notification Progress notification Action button notification Notifications: MainActivity: Refs h

Saul Molinero 191 Nov 29, 2022
πŸ› ThinkRchive Light Dark An app showing all details for various Lenovo Thinkpad models.

?? ThinkRchive Light Dark An app showing all details for various Lenovo Thinkpad models. Made to try out Jepack Compose for Android. This repo is a Mu

Thinkrchive 59 Dec 28, 2022