Giter Club home page Giter Club logo

holdtoloadlayout's Introduction

HoldToLoadLayout

Codacy Badge Build Status Android Arsenal

HoldToLoadLayout is a view group that can contain a single child. It draws your child to middle of layout, and performs loading wheel around it with settings you determined.

Sample Gifs

Anim Anim Anim Anim

Usage

Simply, add a child to HoldToLoadLayout, than set properties about the animation you'd like.

     <com.melih.holdtoload.HoldToLoadLayout
            android:id="@+id/holdToLoadLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/github"/>
        </com.melih.holdtoload.HoldToLoadLayout>
         HoldToLoadLayout holdToLoadLayout = (HoldToLoadLayout) findViewById(R.id.holdToLoadLayout);
         
         holdToLoadLayout.setStrokeWidth(10); // Set stroke width in px ( dp in xml )
         holdToLoadLayout.setStrokeAlpha(255); // Set alpha value of paint ( 0 - 255 )
         holdToLoadLayout.setPlayReverseAnimation(true); // Reverse like it fills, with animation
         holdToLoadLayout.setStopWhenFilled(false); // Stop when holded fully
         holdToLoadLayout.setColorAnimator(Color.YELLOW, Color.RED); // Animate color while drawing
         holdToLoadLayout.setStartAngle(30); // Starting angle of loading

Customization

setStrokeWidth(int strokeWidth)
  • Sets stroke width in pixels if strokewidth is greater than 0.
    You can set dp values from XML. Default is 0.
setPlayReverseAnimation(boolean isReverseAnimationEnabled)
  • If set true, loading will reverse from the point user stopped touching to 0. If set false, loading will disappear instantly.
    Default value is true.
setStopWhenFilled(boolean stopWhenFilled)
  • If set true, loading will stop when it's completed. If set false, loading will be reversed /disappear even if it is filled.
    Default value is true;
setColorAnimator(int startingColor, int endingColor)
  • When set, changes color of loading animation up to progress, starting with startingColor and ending with endingColor.
    There is no color animation by default.
setStrokeColor(int color)
setStrokeColor(String color)
  • Set loading's color. Default color is Color.GREEN ( HoldToLoadLayout.DEFAULT_COLOR ).
setDuration(int durationInMillis)
  • Set duration of fill time in milliseconds. This will throw IllegalArgumentException if durationInMillis is not greater than 0.
    Default value is 1500 ( HoldToLoadLayout.DEFAULT_DURATION ).
setStrokeAlpha(int alpha)
  • Set paint's alpha value. This will throw IllegalArgumentException if alpha is less than 0 or greater than 255.
    Default value is 255 ( HoldToLoadLayout.DEFAULT_ALPHA ).
setStartAngle(float startAngle)
  • Set loading's starting point as angle. Default value is 270 ( top ) ( HoldToLoadLayout.DEFAULT_START_ANGLE ).
setFillListener(FillListener fillListener)
  • Set a fill listener ( HoldToLoadLayout.FillListener() ), which has onFull(), onEmpty() and onAngleChanged(float angle) methods.

XML Attributes

        <attr name="strokeColor" format="string"/>
        <attr name="strokeWidth" format="dimension"/>
        <attr name="strokeAlpha" format="integer"/>
        <attr name="startAngle" format="integer"/>
        <attr name="duration" format="integer"/>
        <attr name="stopWhenFilled" format="boolean"/>

Download

Add it in your root build.gradle at the end of repositories:

allprojects {
		repositories {
			...
			maven { url "https://jitpack.io" }
		}
	}

Add library dependency to your build.gradle file:

dependencies {    
     compile 'com.github.melihaksoy:HoldToLoadLayout:1.0.2'
}

License

The MIT License (MIT)

Copyright (c) 2016 Melihcan Aksoy

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.

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.