Coder Social home page Coder Social logo

loaderviewlibrary's Introduction

Loader View for Android

Android Arsenal

What It Is

Provide both TextView and ImageView the ability to show shimmer (animation loader) before any text or image is shown. Useful when waiting for data to be loaded from the network. Example below

Loader Image

Features / Usage

  1. Loader View for TextView defined in layout XML

    <com.elyeproj.loaderviewlibrary.LoaderTextView
         android:layout_width="match_parent"
         android:layout_height="wrap_content" />
  2. Loader View for ImageView defined in layout XML

    <com.elyeproj.loaderviewlibrary.LoaderImageView
         android:layout_width="100dp"
         android:layout_height="100dp" />
  3. Define the % width of the TextView that shows the loading animation with width_weight

    <com.elyeproj.loaderviewlibrary.LoaderTextView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         app:width_weight="0.4" />
  4. Define the % height of the TextView that shows the loading animation with height_weight

    <com.elyeproj.loaderviewlibrary.LoaderTextView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         app:height_weight="0.8" />
  5. Define use gradient of the TextView or ImageView that shows the gradient with use_gradient

    <com.elyeproj.loaderviewlibrary.LoaderTextView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         app:use_gradient="true" />
  6. Define rectangle round radius using corner. The default corner is 0.

    <com.elyeproj.loaderviewlibrary.LoaderTextView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         app:corners="16" />
  7. Setting the Text Style as BOLD would darken the loading shimmer

  8. Other feature of TextView and ImageView is still applicable.

  9. Use a custom shimmer color (note: if set, point 7 will not apply, your color will be used even if the Text Style is BOLD)

    <com.elyeproj.loaderviewlibrary.LoaderTextView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         app:custom_color="@android:color/holo_green_dark" />
  10. Reset and show shimmer (animation loader) again by calling the below API

    myLoaderTextView.resetLoader();
    myLoaderImageView.resetLoader();

Requirement

Android SDK API Version 15 and above.

Importing the Library

On your root build.gradle, add mavenCentral() to the allprojects section. On your module build.gradle, add

dependencies {
    implementation 'io.github.elye:loaderviewlibrary:3.0.0'
}

What's new in 3.0.0

  1. Moved from JCenter to mavenCenter
  2. Fix some null crash issue

Note: only version 3.0.0 has been moved to mavenCenter

What's new in 2.0.0

  1. Migrate to AndroidX
  2. Fix issue of preventing partial overlay if view reused quickly in RecyclerView

What's new in 1.5.0

  1. Add custom color attribute

Licence

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or 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.

loaderviewlibrary's People

Contributors

alorma avatar cubanjaco avatar donglua avatar elye avatar ema987 avatar hearsilent avatar inlacou avatar mathiasberwig avatar tarun0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

loaderviewlibrary's Issues

Use case in recyclerview

How does it work inside an adapter class??
Use case: I already have a dataset in my listview/recyclerview and I make a swipetorefresh list..
how do I notify the viewholder to start the loading animation while awaiting data from the network ?

Width Weight not support RTL

I am Trying to fix this issue by check Language if its RTL and then draw round rect in reverse.

Is there a better solution?

screen shot 2018-03-02 at 5 52 54 pm

Enable loading view again with setText(null),

Thanks for your great library,
But i want to know how can i enable loading view after setText() method called,
When use LoaderTextView inside RecyclerView adapter and when refreshing the adapter and waiting for server response it will be great to enabled loading view again without re-inflating visible items,

Support of custom views

I am trying to use LoaderViewLibrary in conjunction with custom TextViews and ImageViews, but encontered some issue - LoaderView interface accessibility (LoaderViewLibrary included via Gradle)

Do you have some experience with supporting custom views without need of "re-implementing" them?

Have you considered using LoaderView as layout encapsulating inner views? Similar to e.g.: https://github.com/traex/RippleEffect

decoupling setText and revealing the content

I like the library. I would like to suggest a new functionality. My UI components are built dynamically so I know how many they are only on setText(). The problem is that the loader is never shown.

I think would be interesting decoupling the revealContent() action from the setText() so, even after the text is already in place after calling setText(), the text is not really shown until you run a revealContent() action.

Does this make sense?

Shimmer on editText

Hi! Very nice library. Is it possible to use it on a editTextView?

Thanks

Memory leak

Source code:
valueAnimator.cancel();
setValueAnimator(progress, 0, 0);
valueAnimator.start();
After execution, the animation has been running and has not stopped, causing memory to continue to grow,Debug The onAnimationUpdate monitor is being implemented.

demo error!!!

09-06 10:13:35.894 28244-28244/com.elyeproj.sampleloaderview E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.elyeproj.sampleloaderview, PID: 28244
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.elyeproj.sampleloaderview/com.elyeproj.sampleloaderview.MainActivity}: android.view.InflateException: Binary XML file line #39: Error inflating class
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2187)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2236)
at android.app.ActivityThread.access$800(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5034)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.aurora_org_main(ZygoteInit.java:607)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #39: Error inflating class
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.elyeproj.sampleloaderview.MainActivity.onCreate(MainActivity.java:16)
at android.app.Activity.performCreate(Activity.java:5247)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at com.lbe.security.service.core.client.b.v.callActivityOnCreate(Unknown Source)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2151)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2236) 
at android.app.ActivityThread.access$800(ActivityThread.java:138) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5034) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 
at com.android.internal.os.ZygoteInit.aurora_org_main(ZygoteInit.java:607) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.elyeproj.sampleloaderview.MainActivity.onCreate(MainActivity.java:16) 
at android.app.Activity.performCreate(Activity.java:5247) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
at com.lbe.security.service.core.client.b.v.callActivityOnCreate(Unknown Source) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2151) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2236) 
at android.app.ActivityThread.access$800(ActivityThread.java:138) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5034) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 
at com.android.internal.os.ZygoteInit.aurora_org_main(ZygoteInit.java:607) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.NullPointerException
at com.elyeproj.loaderviewlibrary.LoaderTextView.setRectColor(LoaderTextView.java:86)
at com.elyeproj.loaderviewlibrary.LoaderController.init(LoaderController.java:48)
at com.elyeproj.loaderviewlibrary.LoaderController.(LoaderController.java:43)
at com.elyeproj.loaderviewlibrary.LoaderTextView.init(LoaderTextView.java:56)
at com.elyeproj.loaderviewlibrary.LoaderTextView.(LoaderTextView.java:41)
at java.lang.reflect.Constructor.constructNative(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
at android.view.LayoutInflater.createView(LayoutInflater.java:594) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.elyeproj.sampleloaderview.MainActivity.onCreate(MainActivity.java:16) 
at android.app.Activity.performCreate(Activity.java:5247) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
at com.lbe.security.service.core.client.b.v.callActivityOnCreate(Unknown Source) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2151) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2236) 
at android.app.ActivityThread.access$800(ActivityThread.java:138) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5034) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 
at com.android.internal.os.ZygoteInit.aurora_org_main(ZygoteInit.java:607) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565) 
at dalvik.system.NativeStart.main(Native Method) 

LoaderImageView leaks memory

LoaderImageView leaks memory as it holds the context of the activity.
Please check the below screenshot from Leakcanary

image

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.