android-pulse-indicator

Additional

Language
Java
Version
N/A
Created
Aug 20, 2016
Updated
Aug 22, 2016 (Retired)
Owner
jackpocket
Contributor
Matt Silber (mattsilber)
1
Activity
Badge
Generate
Download
Source code

Advertising

pulse-indicator

An Android View system for indicating Views using fading pulses

Installation

    repositories {
        jcenter()
    }

    dependencies {
        compile('com.jackpocket:pulse-indicator:1.0.4')
    }

Usage

Layout Approach

Make the root of your Activity's layout one of the base PulseLayouts included in this library: the PulsingLinearLayout or the PulsingRelativeLayout. e.g.

<com.jackpocket.pulse.layouts.PulsingLinearLayout 
    ...
    >

Then find it in your Activity and simply call PulseLayout.attachTo(Activity, View). Done. e.g.

((PulseLayout) findViewById(R.id.my_pulsing_layout))
    .attachTo(this, findViewById(R.id.some_view_I_want_to_indicate);
PulseView Approach

Just add a PulseView to your layout (make sure you're using a ViewGroup that allows overlapping children (e.g. RelativeLayout)).

<RelativeLayout>
    <com.jackpocket.pulse.layouts.PulseView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        ... />
</RelativeLayout>

You could then use it the same way you would going the Layout Approach mentioned above.

Custom Approach

If you want to add pulsing to your own custom layouts, just checkout one of the supplied layout class files for detailed information on how to implemented the PulsingController manually.

Changing the values at runtime can also be configured by working with the PulseController:

((PulseLayout) findViewById(R.id.my_pulsing_layout))
    .attachTo(this, findViewById(R.id.some_view_I_want_to_indicate)
        .setCirclePathOverride(false) // Set it to use the rectangular boundaries instead of circle pulsing
        .setPulsingColor(0xFF22FF22) // Set the pulse starting color
        .setPulsingStrokeWidth(10) // Override the dynamic stroke width with a custom one
        .setDurationMs(1500) // Set the overall duration of the pulsing (will continue until no pulses exist)
        .setPulseLifespanMs(900) // The length of time a pulse is visible
        .setRespawnRateMs(300) // The rate at which a new pulse should be added
        .setAlphaInterpolator(new AccelerateInterpolator()) // Set the Interpolator for the alpha animation
        .setScaleInterpolator(new LinearInterpolator()) // Set the Interpolator for the scaling animation
        .setFinishedListener(view -> doSomethingOnFinished()); // Set a callback to be triggered when the pulsing finished for a View. Calling attach() before it completes will prevent it from being triggered

Configs

The default configs for pulsing color, duration, individual lifespan, respawn rates can be overwritten via the following, respectively:

R.color.pulse__color
R.integer.pulse__duration_default
R.integer.pulse__lifespan_default
R.integer.pulse__respawn_rate_default

Note, all time values are in milliseconds.