Giter VIP home page Giter VIP logo

coloredshadowimageview's Introduction

ColoredShadowImageView

ColoredShadowImageView allows you to create a beautiful shadow around the image based on corresponding area colors.

Download sample apk

The current minSDK version is API level 16.

Download ⬇️


Gradle:

implementation 'com.github.armcha:ColoredShadowImageView:1.1.0'

Setup and usage

  1. You also need to add RenderScript to your app module. Add these lines to the defaultConfig block of your build.gradle.
renderscriptTargetApi YOUR_TARGET_SDK_VERSION
renderscriptSupportModeEnabled true 
  1. Static image
<io.github.armcha.coloredshadow.ShadowImageView
        android:id="@+id/shadowImage"
        android:layout_width="300dp"
        android:layout_height="400dp"
        android:src="@drawable/android"/>

Or

  findViewById<ShadowImageView>(R.id.shadowImage).apply {
       setImageResource(R.drawable.android)
  }
  1. If you are using Glide, use it in this way. Glide transformations are also supported. Now we have some limitations for Glide transitions.
//shadowView.radiusOffset = 0.4f
//shadowView.shadowColor = ContextCompat.getColor(context,R.color.green)

GlideApp.with(itemView.context)
                    .load(item.imageUrl)
                    .placeholder(R.drawable.place_holder)
                    .error(R.drawable.place_holder)
                    //.transform(CircleCrop())
                    .into(object : ViewTarget<ImageView, Drawable>(shadowView) {
                        override fun onLoadStarted(placeholder: Drawable?) {
                            super.onLoadStarted(placeholder)
                            shadowView.setImageDrawable(placeholder, withShadow = false)
                        }

                        override fun onLoadCleared(placeholder: Drawable?) {
                            super.onLoadCleared(placeholder)
                            shadowView.setImageDrawable(placeholder, withShadow = false)
                        }

                        override fun onLoadFailed(errorDrawable: Drawable?) {
                            super.onLoadFailed(errorDrawable)
                            shadowView.setImageDrawable(errorDrawable, withShadow = false)
                        }

                        override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
                            shadowView.setImageDrawable(resource)
                        }
                    })

Customizations

You can change shadow radius. Default radius is 0.5. You can change it between 0 and 1. (0 < radius ≤ 1)

  shadowImageView.radiusOffset = 0.4f
  shadowImageView.setImageResource(R.drawable.android)

You can also change the shadow color

  shadowImageView.shadowColor = ContextCompat.getColor(context,R.color.green) //or Color.RED
  shadowImageView.setImageResource(R.drawable.android)

or from xml

   app:radiusOffset="0.6"
   app:shadowColor="@color/colorAccent"

Current limitations: 🚩

  • You can't use the library when setting width or height to WRAP_CONTENT

Add proguard rules if necessary:

-keep class android.support.v8.renderscript.** { *; }

Contact 📖

Pull requests are more than welcome.

▶️ Email: [email protected]

▶️ Medium: https://medium.com/@chatikyan

▶️ Twitter: https://twitter.com/ArmanChatikyan

▶️ Facebook: https://web.facebook.com/chatikyana

▶️ Google +: https://plus.google.com/+ArmanChatikyan

▶️ Website: https://armcha.github.io/

License

  ColoredShadowImageView
  Copyright (c) 2018 Arman Chatikyan (https://github.com/armcha/ColoredShadowImageView).

  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.

coloredshadowimageview's People

Contributors

armcha avatar hearsilent avatar

Watchers

 avatar

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.