Code Monkey home page Code Monkey logo

vectorintegerview's Introduction

VectorIntegerView

VectorIntegerView (viv) is custom view to display integers on Android via great animations minSdkVersion 21.

Paths for vector drawables drawables are taken here.

Article on Habr.com

art

Customizing

VectorIntegerView has following XML-attributes:

  • viv_vector_integer initial integer to show (0 by default).
  • viv_digit_color color of integer (black by default).

Other properties may be configured by overriding resourses from library:

(those will be applied to all VectorIntegerView in app, for example see demo-app)

  • @integer/viv_animation_duration defines duration of animation (400ms by default).
  • @dimen/viv_digit_size defines size of one digit (24dp by default).
  • @dimen/viv_digit_translateX applied to all avd-digits, to center them horizontally.
  • @dimen/viv_digit_translateY applied to all avd-digits, to center them vertically.
  • @dimen/viv_digit_strokewidth applied to all avd-digits.
  • @dimen/viv_digit_margin_horizontal applied to all digit-views (-3dp by default). This is needed to make horizontal spaces between digits smaller, because avd-digits are square.

In code

XML

<com.qwert2603.vector_integer_view.VectorIntegerView
    android:id="@+id/vectorIntegerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="16dp"
    app:viv_digit_color="#ff8000"
    app:viv_vector_integer="14" />

Java / Kotlin

Digit can be set also via code as BigInteger as well as digit color:

final VectorIntegerView vectorIntegerView = findViewById(R.id.vectorIntegerView);
vectorIntegerView.setInteger(
        vectorIntegerView.getInteger().add(BigInteger.ONE),
        /* animated = */ true
);
vectorIntegerView.setDigitColor(getColor(R.color.colorAccent));

Also there is overloaded function that allows set integer as long:

vectorIntegerView.setInteger(1918L, false);

For example see demo-app.

Under the hood

VectorIntegerView is implemented by RecyclerView and each digit is ImageView with <animated-selector> drawable.

Animation are controlled by custom RecyclerView's item animator: DigitItemAnimator.

When animated each digit stays on it's own position. This is done via DiffUtil in DigitAdapter.

Download

allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}
dependencies {
        implementation 'com.github.qwert2603:VectorIntegerView:x.y.z'
}

vectorintegerview's People

Contributors

qwert2603 avatar

Watchers

James Cloos 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.