HoldToLoadLayout

Additional

Language
Java
Version
1.0.6 (Dec 29, 2016)
Created
Jun 13, 2016
Updated
Sep 19, 2017 (Retired)
Owner
Melih Aksoy (melihaksoy)
Contributor
Melih Aksoy (melihaksoy)
1
Activity
Badge
Generate
Download
Source code

HoldToLoadLayout

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

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.