A layout that creates a loading-like progress around it's child ( circle ) on touch, inspired from Destiny's ( PS4 ) accept mechanism

Overview

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 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(Angle.TOP); // Use any of the pre-defined starting angle
         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.
    Does NOT updates stroke width dynamically.
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;
setHoldAtLastPosition(boolean isHoldAtLastPosition)
  • If set true, progress will not be reverted or reset when user lifts up his/her finger. This will suppress stopWhenFilled and setPlayReverseAnimation.
    Default value is false.
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 ).
    Does NOT updates color dynamically.
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(Angle startAngle)
  • Set loading's starting point from pre-defined angles. Default value is Angle.TOP
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(), onAngleChanged(float angle) and onOffsetChanged(float offset)methods.
    Setting null will remove the listener.
setFillListener(FillListener fillListener)
  • Set a fill listener ( HoldToLoadLayout.FillListener() ), which has onFull(), onEmpty() and onAngleChanged(float angle) methods.
removeFillListener()
  • Removes fill listener.

XML Attributes

        <attr name="hold_strokeColor" format="string"/>
        		<attr name="hold_strokeWidth" format="dimension"/>
        		<attr name="hold_strokeAlpha" format="integer"/>
        		<attr name="hold_duration" format="integer"/>
        		<attr name="hold_stopWhenFilled" format="boolean"/>
        		<attr name="hold_startAngle" format="float"/>

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.7'
}

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.
You might also like...
This assignment gives you basically a post list and its detail with comments.🚀
This assignment gives you basically a post list and its detail with comments.🚀

Android Assignment 📜 Description This assignment gives you basically a post list and its detail with comments. 📱 Features Users can see random post

:octocat: 📃  FoldingCell is a material design expanding content cell inspired by folding paper material made by @Ramotion
:octocat: 📃 FoldingCell is a material design expanding content cell inspired by folding paper material made by @Ramotion

FOLDING CELL [JAVA] Expanding content cell with animation inspired by folding paper card material design. We specialize in the designing and coding of

The Most Powerful Swipe Layout!
The Most Powerful Swipe Layout!

Android Swipe Layout ![Gitter](https://badges.gitter.im/Join Chat.svg) This is the brother of AndroidViewHover. One year ago, I started to make an app

A very simple arc layout library for Android
A very simple arc layout library for Android

ArcLayout A very simple arc layout library for Android. Try out the sample application on the Play Store. Usage (For a working implementation of this

Android layout that simulates physics using JBox2D
Android layout that simulates physics using JBox2D

PhysicsLayout Android layout that simulates physics using JBox2D. Simply add views, enable physics, and watch them fall! See it in action with the sam

a custom pull-to-refresh layout which contains a interesting animation
a custom pull-to-refresh layout which contains a interesting animation

This is a project with custom pull-to-refresh layout which contains a interesting animation. And the animation is inspired by https://dribbble.com/sho

A layout to transition between two views using a Floating Action Button as shown in many Material Design concepts
A layout to transition between two views using a Floating Action Button as shown in many Material Design concepts

⚠ This library is no longer maintained ⚠️ FABRevealLayout A layout to transition between two views using a Floating Action Button as shown in many Mat

An Android demo of a foldable layout implementation. Engineered by Vincent Brison.
An Android demo of a foldable layout implementation. Engineered by Vincent Brison.

Foldable Layout This code is a showcase of a foldable animation I created for Worldline. The code is fully written with java APIs from the Android SDK

A 3D Layout for Android,When you use it warp other view,it can became a 3D view,一秒让你的view拥有3D效果!
A 3D Layout for Android,When you use it warp other view,it can became a 3D view,一秒让你的view拥有3D效果!

ThreeDLayout A 3D Layout,When you use it warp other view,it can became a 3D view 中文文档 preview USAGE 1.compile library allprojects { repositories {

Comments
  • Can't stop before given time

    Can't stop before given time

    Hi. I want to do this animation work for at max 30 second. But it can be stopped anytime among 1-30 seconds. How can i stopped that . I have also tried to stop by modifying your class:

    public void myStopper(){
        stopForwardProgressAnimator();
        stopReverseProgressAnimator();
        stopReverseColorAnimator();
        stopForwardColorAnimator();
    
    }
    

    But still not working

    enhancement 
    opened by sulaimansust 2
  • setStrokeColor() does not work?

    setStrokeColor() does not work?

    I did this:

     button.setFillListener(new HoldToLoadLayout.FillListener() {
            @Override
            public void onFull() {
                button.setStrokeColor(R.color.target_green);
                button.setDuration(1000);
            }
    
            @Override
            public void onEmpty() {
                button.setStrokeColor(R.color.blue_accent);
                button.setDuration(2000);
            }
        });
    

    The duration changes correctly, while the color does not... Am I doing something wrong?

    enhancement 
    opened by adamzimnyy 2
  • Attribute

    Attribute "strokeColor" has already been defined and "StrokeWidth"

    Hello college,

    I have a problem with this attributes, Error:(289) Attribute "strokeColor" has already been defined Error:(289) Attribute "strokeWidth" has already been defined Because this params are same that the third party library "CirclePageIndicator".

    I like your pretty library and i would like that i can use it. (Can you change the name writing a prefix?)

    Thank you n1rocket

    opened by n1rocket 2
  • ScrollView + HoldToLoadLayout

    ScrollView + HoldToLoadLayout

    Hello again, I'm testing the library into a ScrollView and when i press the button and scroll, the component continues running and finish without press more.

    I hope you will could understand me, my english isn't good.

    thanks you!

    opened by abuenovanadis 2
Owner
Melih Aksoy
Android Engineer
Melih Aksoy
An Android layout for arranging children along a circle

CircleLayout An Android layout for arranging children along a circle You can customize the following options: cl_centerView: Set a specific view ID to

Francois Campbell 374 Nov 18, 2022
Android implementation of FlowLayout. Layout arranges its children in multiple rows depending on their width.

FlowLayout FlowLayout is an opensource Android library that alows developers to easily integrate flow layout into their app. FlowLayout is an layout t

Blaž Šolar 754 Dec 15, 2022
Android - A layout that arranges its children in relation to a background image

ImageLayout A layout that arranges its children in relation to a background image. The layout of each child is specified in image coordinates (pixels)

Manuel Peinado Gallego 419 Nov 14, 2022
Linear layout, that wrap its content to the next line if there is no space in the current line.

Android flow layout Introduction Extended linear layout that wrap its content when there is no place in the current line. [] (https://travis-ci.org/Ap

Artem.Votincev 2k Jan 5, 2023
A pull-down-to-refresh layout inspired by Lollipop overscrolled effects

JellyRefreshLayout A pull-down-to-refresh layout inspired by Lollipop overscrolled effects Preview Download Gradle: repositories { maven {

Y.Chen 628 Oct 26, 2022
GoolgePlusLayout is a custom layout that plays animation on the children views while scrolling as the layout in the Google Plus (android) main page

Google Plus Layout Google Plus Layout is a custom layout that support playing animation on child view(s) in a serialize manner like the the main

Ahmed Nammari 224 Nov 25, 2022
Responsive Layout Gird Configuration using Compose. An adaptive layout

ResponsiveGrid Responsive Grid is most followed layout system by the designer as it adapts to screen size and orientation, ensuring consistency across

null 4 Apr 12, 2022
ViewStateLayout - Easy way to manage common state templates like loading, empty, error etc.!

ViewStateLayout Easy way to manage common state templates like loading, empty, error etc.! How to Step 1. Add the JitPack repository to your build fil

Kamrul Hasan 7 Dec 15, 2022
An Android Layout which has a same function like https://github.com/romaonthego/RESideMenu

ResideLayout An Android Layout which has a same function like https://github.com/romaonthego/RESideMenu. Can be used on Android 1.6(I haven't try it.)

Yang Hui 392 Oct 12, 2022