AndroidFillableLoaders


Source link: https://github.com/JorgeCastilloPrz/AndroidFillableLoaders

Android FillableLoaders

Android Open Source library providing an interesting fillable progress view working with SVG paths. This is a nice option too if you want to create an interesting branding logo for your app.

Check this blog post in order to get more technical details about the library.

Sample Video

Youtube Sample Video

Screenshots

How to

As the library works with a standard String formatted source SVG Path, you need to generate it with some external tool. I usually use GIMP for that, as it has an interesting support to generate SVG Paths from original images. Here is the needed documentation to do it.

After that, set your generated path to the view. Be careful to just take the path, and not the full xml content generated. The path will look something like:

M 2948.00,18.00
 C 2956.86,18.01 2954.31,18.45 2962.00,19.91

3009.70,28.94 3043.56,69.15 3043.00,118.00

3042.94,122.96 3042.06,127.15 3041.25,132.00

3036.37,161.02 3020.92,184.46 2996.00,200.31

2976.23,212.88 2959.60,214.26 2937.00,214.00

2926.91,213.88 2912.06,209.70 2903.00,205.24

2893.00,200.33 2884.08,194.74 2876.04,186.91

2848.21,159.81 2839.19,115.93 2853.45,80.00

2863.41,54.91 2883.01,35.57 2908.00,25.45

2916.97,21.82 2924.84,20.75 2934.00,18.51

2938.63,17.79 2943.32,17.99 2948.00,18.00 Z
 M 2870.76,78.00
 ... 

To set the generated path by code (do it just if you declared FillableLoader in the xml layout):

fillableLoader.setSvgPath(String generatedSvgPath);

And to include it into your layout:

<com.github.jorgecastillo.FillableLoader
android:id="@+id/fillableLoader"
android:layout_width="200dp"
android:layout_height="100dp"
app:fl_originalWidth="@integer/original_svg_width"
app:fl_originalHeight="@integer/original_svg_height"
app:fl_strokeColor="@color/stroke_color"
app:fl_fillColor="@color/fill_color"
app:fl_strokeWidth="@dimen/stroke_width"
app:fl_strokeDrawingDuration="@integer/stroke_drawing_duration"
app:fl_fillDuration="@integer/fill_duration"
app:fl_clippingTransform="waves"
app:fl_fillPercentage="@integer/fill_percentage"
/>
 <!--   Default supported clipping transforms: "plain", "spikes", "rounded", "waves", "squares" and "bites".   Read "Customize filling" section to implement a custom one.   -->

Or if you rather you can do it by code using the FillableLoaderBuilder class. It will get automatically attached to the given parent view. Use the LayoutParams argument to position it:

FillableLoaderBuilder loaderBuilder = new FillableLoaderBuilder();
 fillableLoader = loaderBuilder
  .parentView((FrameLayout) rootView)
  .layoutParams(params)
  .svgPath(Paths.JOB_AND_TALENT)
  .originalDimensions(970, 970)
  .strokeWidth(strokeWidth)
  .strokeColor(Color.parseColor("#1c9ade"))
  .fillColor(Color.parseColor("#1c9ade"))
  .strokeDrawingDuration(2000)
  .fillDuration(5000)
  .clippingTransform(new PlainClippingTransform())
  .build();

The only required arguments which does not have default values are the original dimensions from the svg image, and the svg path. Both of them are needed in order to get everything working properly. You can omit the other ones if you want.

Listen to State change

In order to allow reaction to every State switch ( NOT_STARTED -> TRACE_STARTED -> FILL_STARTED -> FINISHED) you must implement OnStateChangeListener and override its onStateChange(int state) method.

@Override public void onStateChange(int state) {

((MainActivity) getActivity()).showStateHint(state);

 switch(state) {

  case State.FILL_STARTED:

 ...

 break;
  case State.FINISHED:

 ...

}
 
}

Customize filling

To get a custom "top border" style for the filling figure, you can implement the ClippingTransform interface, which will force you to create an implementation for the transform() method.

You must think about the clipping figure as an invisible polygon that is going to clip your filling figure. (Like a DIFFERENCE operation between the total filling space and the custom transform figure you are applying). It must vary depending on the currentFillPhase.

public class PlainClippingTransform implements ClippingTransform {

 @Override public void transform(Canvas canvas, float currentFillPhase, View view) {

  canvas.clipRect(0, (view.getBottom() - view.getTop()) * (1f - currentFillPhase),

view.getRight(), view.getBottom());

}
 
}

The canvas would be the one used to draw the loader, the currentFillPhase argument is the current percent of the animation step (from 0 to 1), and the view would need to be provided too, so it can be used to create an animation based on view properties, like its current dimensions.

Custom behavior

If your loader / brand logo needs to you can suppress the stroke drawing animation and go directly for the filling one. To do that, just set app:strokeDrawingDuration="0".

If you only need to fill the pattern partially or you want to control the fill progress, you can use fl_fillPercentage xml (resource) property or if you want to control from Java use.

fillableLoader.setPercentage(percent);

Add it to your project

If you are working with gradle, add the dependency to your build.gradle file:

dependencies{

  compile 'com.github.jorgecastilloprz:fillableloaders:1.03@aar' 
}

if you are working with maven, do it into your pom.xml

<dependency>
  <groupId>com.github.jorgecastilloprz</groupId>
  <artifactId>fillableloaders</artifactId>
  <version>1.03</version>
  <type>aar</type> </dependency>

Documentation

You can find a detailed explanation of the lib functionality in this blog post.

Attributions

  • The class SvgPathParser used to convert from String SVG Path format to Android SDK Path structures has been obtained from the interesting romannurik Muzei code.
  • This project has been inspired by this iOS Swift project created by poolqf.

Developed By

License

Copyright 2015 Jorge Castillo PĂ©rez  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

The HttpResponseCache library provides transparent and automatic caching of HTTP and HTTPS requests that use the java.net.HttpUrlConnection classes.

For information on how to use HttpUrlConnection, refer to the Android documentation - don't worry, the information also applies to non-Android Java.

Smooth activity switch animation.

PoppyView is a library which implements view on the bottom which come and go relative to the user scroll.

Just add the library to your application as a library project. And don't forget that your project must use NineOldAndroids.

A small library replicating the new dialogs in Android L.

Just as there was Retroweaver et al. for running Java 5 code with generics on Java 1.4, Retrolambda lets you run Java 8 code with lambda expressions on Java 7 or lower. It does this by transforming your Java 8 compiled bytecode so that it can run on a Java 7 runtime. After the transformation they are just a bunch of normal .class files, without adding any runtime dependencies.

ViewServer is a simple class you can use in your Android application to use the HierarchyViewer inspection tool.

ViewServer requires the Android SDK r12 or higher. http://developer.android.com/sdk/index.html

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes