================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2020 Vivek Verma
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.
================================================
FILE: README.md
================================================
This library provides blurred drop shadows to ImageView similar to iOS backdrop shadows.Provides fast canvas draw as no renderscript needed .The similar shadow blurred effects can also be seen in iOS Music App.
# Download Demo App
Download the demo app .apk file here
## Scan to Download
# Installation
Add it in your root build.gradle at the end of repositories :
```gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```
Add the following dependency to your app build.gradle file :
```gradle
dependencies {
implementation 'com.github.virtualvivek:BlurShadowImageView:4.0'
}
```
# How to use
## Using Xml to config
```xml
```
## Use Java code to config
```js
BlurShadowImageView blurshadowimageview = findViewById(R.id.blurSImageView);
//Sets Border Round Radius
blurshadowimageview.setRound((int) value);
//Sets Image Resource
blurshadowimageview.setImageResource(ImgRes);
//Sets Image Drawable
blurshadowimageview.setImageDrawable(drawable);
//Sets Image Bitmap
blurshadowimageview.setImageBitmap(bitmap);
```
# Load image with Picasso
```js
Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap,
Picasso.LoadedFrom from) {
// Bitmap is loaded, use Image here
demo_img.setImageBitmap(bitmap);
}
@Override
public void onBitmapFailed(Exception e, Drawable d) {
// Fires if bitmap couldn't be loaded.
}
@Override
public void onPrepareLoad(Drawable d){
// Fires bitmap on prepare.
}
};
//Use this target for the Picasso.into() method
Picasso.get().load("https://i.imgur.com/DvpvklR.png").into(target);
```
# Image Blur Backdrop Offset
# Documentation
```yaml
app:v_imageSrc: "../refrence"
```
```yaml
app:v_imageRound: "(int)dp"
```
```yaml
app:v_shadowOffset: "(int)dp"
```
```yaml
android:scaleType: ["center","centerCrop","fitEnd","fitCenter","fitXY","centerInside","fitStart","matrix"]
```
|Name|Format|Default|Details|
|:---:|:---:|:---:|:---:|
|app:v_imageSrc |reference|image|sets image to the ImageView|
|app:v_imageRound |dimension|10dp|sets border radius to the ImageView|
|app:v_shadowOffset|dimension|40dp|configure the distance between the Image and the Shadow|
|android:scaleType|string|"centerCrop"|configure the Image scaling|
## Find this library useful? :heart:
Support it by joining [**stargazers**](https://github.com/virtualvivek/BlurShadowImageView/stargazers) for this repository. :star:
# Branches
Branch -version 4.x [ AndroidX ] ‣ Current Branch
Branch -version 1.x Support LibraryView Branch
# License
BlurShadowImageView is licensed under `MIT license`. View [license](https://github.com/virtualvivek/BlurShadowImageView/blob/master/LICENSE).
Copyright (c) 2020-24 [**Vivek Verma**](https://github.com/virtualvivek)
================================================
FILE: app/.gitignore
================================================
/build
================================================
FILE: app/app.iml
================================================
generateDebugSources
================================================
FILE: app/build.gradle
================================================
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "me.virtualiz.blurshadowimageview"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.1"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'com.google.android.material:material:1.2.0'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.squareup.picasso:picasso:2.71828'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation project(':library')
}
================================================
FILE: app/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Users\x\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
================================================
FILE: app/src/main/AndroidManifest.xml
================================================
================================================
FILE: app/src/main/java/me/virtualiz/blurshadowimageviewEx/MainActivity.java
================================================
package me.virtualiz.blurshadowimageviewEx;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;
import me.virtualiz.blurshadowimageview.BlurShadowImageView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().hide();
Button buttonLink = findViewById(R.id.buttonLink);
final BlurShadowImageView demo_img = findViewById(R.id.demo_img);
Button load_image_button = findViewById(R.id.buttonLoadImg);
demo_img.setImageResource(R.drawable.ironman_80);
load_image_button.setOnClickListener((View v)-> {
Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
// Bitmap is loaded, use image here
demo_img.setImageBitmap(bitmap);
}
@Override
public void onBitmapFailed(Exception e, Drawable d) {
// Fires if bitmap couldn't be loaded.
}
@Override
public void onPrepareLoad(Drawable d){
// Fires bitmap on prepare.
}
};
Picasso.get().load("https://i.imgur.com/DvpvklR.png").into(target);
});
buttonLink.setOnClickListener((View v)-> {
Uri uri = Uri.parse("https://www.github.com/virtualvivek/BlurShadowImageView");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
});
TextView link_text = findViewById(R.id.link_text);
link_text.setOnClickListener((View v)-> {
Uri uri = Uri.parse("https://www.github.com/virtualvivek/BlurShadowImageView");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
});
}
}
================================================
FILE: app/src/main/res/drawable/background_green_round_touchlistner.xml
================================================
================================================
FILE: app/src/main/res/drawable/background_green_round_touchlistner_presses.xml
================================================
================================================
FILE: app/src/main/res/drawable/background_green_round_touchlistner_selector.xml
================================================
================================================
FILE: app/src/main/res/drawable/background_white_round_touchlistner.xml
================================================
================================================
FILE: app/src/main/res/drawable/background_white_round_touchlistner_presses.xml
================================================
================================================
FILE: app/src/main/res/drawable/background_white_round_touchlistner_selector.xml
================================================
================================================
FILE: app/src/main/res/drawable/github.xml
================================================
================================================
FILE: app/src/main/res/layout/activity_main.xml
================================================
================================================
FILE: app/src/main/res/values/colors.xml
================================================
#EEE#999#FF4081#EEEEEE
================================================
FILE: app/src/main/res/values/strings.xml
================================================
BlurShadowImageView
================================================
FILE: app/src/main/res/values/styles.xml
================================================
================================================
FILE: build.gradle
================================================
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
================================================
FILE: gradle/wrapper/gradle-wrapper.properties
================================================
#Mon Sep 30 13:46:21 IST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
================================================
FILE: gradle.properties
================================================
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
================================================
FILE: gradlew
================================================
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
================================================
FILE: gradlew.bat
================================================
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
================================================
FILE: library/.gitignore
================================================
/build
================================================
FILE: library/build.gradle
================================================
apply plugin: 'com.android.library'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.1"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
================================================
FILE: library/library.iml
================================================
generateDebugSources
================================================
FILE: library/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Users\x\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
================================================
FILE: library/src/androidTest/java/me/virtualiz/blurshadowimageview/ExampleInstrumentedTest.java
================================================
package me.virtualiz.blurshadowimageview;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumentation test, which will execute on an Android device.
*
* @see Testing documentation
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("me.virtualiz.blurshadowimageview.test", appContext.getPackageName());
}
}
================================================
FILE: library/src/main/AndroidManifest.xml
================================================
================================================
FILE: library/src/main/java/me/virtualiz/blurshadowimageview/BlurShadowImageView.java
================================================
/*
* Copyright 2021 vivekverma
*
* Licensed under the MIT License, (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://github.com/virtualvivek/BlurShadowImageView/blob/main/LICENSE
*
* 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.
*/
package me.virtualiz.blurshadowimageview;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import me.virtualiz.blurshadowimageview.helper.FadingImageView;
import me.virtualiz.blurshadowimageview.helper.RoundImageView;
/**
* ================================================
* virtualvivek7@gmail.com
* -version:4.0
* -updated :1 Sep 2021
* Developed by:
* Vivek Verma
* ================================================
*/
public class BlurShadowImageView extends RelativeLayout {
private int imageRound = dpToPx(10);
private int shadowOffset = dpToPx(50);
boolean mInvalidat;
private Bitmap blurredImage;
public BlurShadowImageView(Context context) {
this(context, null);
}
public BlurShadowImageView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public BlurShadowImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView(context, attrs);
}
public static int dpToPx(int dp){
return (int) (dp* Resources.getSystem().getDisplayMetrics().density);
}
private void initView(Context context, AttributeSet attrs) {
RoundImageView roundImageView = new RoundImageView(context);
FadingImageView blurImageView = new FadingImageView(context);
int imageresource, imageScaleTypeIndex;
setGravity(Gravity.CENTER);
setLayerType(LAYER_TYPE_SOFTWARE, null);
imageresource = -1;
if (attrs != null) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BlurShadowImageView);
if (a.hasValue(R.styleable.BlurShadowImageView_v_imageSrc)) {
imageresource = a.getResourceId(R.styleable.BlurShadowImageView_v_imageSrc, -1);
}
imageRound = a.getDimensionPixelSize(R.styleable.BlurShadowImageView_v_imageRound, imageRound);
shadowOffset = a.getDimensionPixelSize(R.styleable.BlurShadowImageView_v_shadowOffset, shadowOffset);
imageScaleTypeIndex = a.getInt(R.styleable.BlurShadowImageView_android_scaleType, -1);
if (imageScaleTypeIndex >= 0) {
ImageView.ScaleType[] types = ImageView.ScaleType.values();
ImageView.ScaleType scaleType = types[imageScaleTypeIndex];
roundImageView.setScaleType(scaleType);
}
else {
roundImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
}
a.recycle();
}
else {
float density = context.getResources().getDisplayMetrics().density;
imageRound = (int) (imageRound * density);
imageresource = -1;
}
//---- Layer ImageView ---------------------------------------------------------------------
if (imageresource == -1) {
roundImageView.setImageResource(android.R.color.transparent);
} else {
roundImageView.setImageResource(imageresource);
}
//---- Layer BlurView ----------------------------------------------------------------------
blurImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
//Blurring techinique without renderscript --------------
if (imageresource == -1) {
Bitmap image = Bitmap.createBitmap(20, 20, Bitmap.Config.ARGB_8888);
image.eraseColor(Color.LTGRAY);
blurImageView.setImageBitmap(image);
}
else {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),imageresource);
if (!isInEditMode()) {
blurredImage = Bitmap.createScaledBitmap(bitmap,8,8,true);
blurImageView.setImageBitmap(blurredImage);
}
//IF is on Edit mode render Basic Shadow to avoid rendering issue
else {
BitmapDrawable bitmapDrawable = new BitmapDrawable(context.getResources(),bitmap);
bitmapDrawable.setColorFilter(0xff999999, PorterDuff.Mode.ADD);
blurImageView.setImageDrawable(bitmapDrawable);
}
}
// Setting Layour For BlurView --
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
blurImageView.setLayoutParams(lp);
// Setting Layout for RoundImageView --
RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
lp2.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
lp2.setMargins(dpToPx(15),0,dpToPx(15),shadowOffset);
roundImageView.setLayoutParams(lp2);
addView(blurImageView);
addView(roundImageView);
getViewTreeObserver().addOnGlobalLayoutListener(()-> {
int N = getChildCount();
for (int i = 0; i < N; i++) {
N = getChildCount();
}
((RoundImageView) getChildAt(1)).setRound(imageRound);
mInvalidat = true;
});
}
public void setImageResource(int resId) {
//Setting RoundedImageView layer
((RoundImageView) getChildAt(1)).setImageResource(resId);
//Setting FadedBlurredImageView layer
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),resId);
blurredImage = Bitmap.createScaledBitmap(bitmap,8,8,true);
((FadingImageView) getChildAt(0)).setImageBitmap(blurredImage);
invalidate();
mInvalidat = true;
}
public void setImageDrawable(Drawable drawable) {
//Setting RoundedImageView layer
((RoundImageView) getChildAt(1)).setImageDrawable(drawable);
//Setting FadedBlurredImageView layer
Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
blurredImage = Bitmap.createScaledBitmap(bitmap,8,8,true);
((FadingImageView) getChildAt(0)).setImageBitmap(blurredImage);
invalidate();
mInvalidat = true;
}
public void setImageBitmap(Bitmap bitmap) {
//Setting RoundedImageView layer
((RoundImageView) getChildAt(1)).setImageBitmap(bitmap);
//Setting FadedBlurredImageView layer
blurredImage = Bitmap.createScaledBitmap(bitmap,8,8,true);
((FadingImageView) getChildAt(0)).setImageBitmap(blurredImage);
invalidate();
mInvalidat = true;
}
public void setImageRadius(int radius_) {
if (radius_ > getChildAt(1).getWidth() / 2 || radius_ > getChildAt(1).getHeight() / 2) {
if (getChildAt(1).getWidth() > getChildAt(1).getHeight()) {
radius_ = getChildAt(1).getHeight() / 2;
} else {
radius_ = getChildAt(1).getWidth() / 2;
}
}
this.imageRound = radius_;
((RoundImageView) getChildAt(1)).setRound(imageRound);
invalidate();
mInvalidat = true;
}
}
================================================
FILE: library/src/main/java/me/virtualiz/blurshadowimageview/helper/FadingImageView.java
================================================
package me.virtualiz.blurshadowimageview.helper;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.widget.ImageView;
@SuppressLint("AppCompatCustomView")
public class FadingImageView extends ImageView {
private boolean mFadeRight;
private boolean mFadeLeft;
private boolean mFadeTop;
private boolean mFadeBottom;
private Paint paint2;
private Context c;
public FadingImageView(Context c, AttributeSet attrs, int defStyle) {
super(c, attrs, defStyle);
this.c = c;
init();
}
public FadingImageView(Context c, AttributeSet attrs) {
super(c, attrs);
this.c = c;
init();
}
public FadingImageView(Context c) {
super(c);
this.c = c;
init();
}
private void init() {
Paint paint;
// Enable horizontal fading
this.setHorizontalFadingEdgeEnabled(true);
this.setVerticalFadingEdgeEnabled(true);
// Apply default fading length
this.setEdgeLength(78);
// Apply default side
this.setFadeRight(true);
this.setFadeLeft(true);
this.setFadeBottom(true);
this.setFadeTop(true);
//code to round the fadded view
paint = new Paint();
paint.setColor(Color.WHITE);
paint.setAntiAlias(true);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
paint2 = new Paint();
paint2.setXfermode(null);
}
public void setFadeRight(boolean fadeRight) {
mFadeRight = fadeRight;
}
public void setFadeLeft(boolean fadeLeft) {
mFadeLeft = fadeLeft;
}
public void setFadeTop(boolean fadeTop) {
mFadeTop = fadeTop;
}
public void setFadeBottom(boolean fadeBottom) {
mFadeBottom = fadeBottom;
}
public void setEdgeLength(int length) {
this.setFadingEdgeLength(getPixels(length));
}
@Override
protected float getTopFadingEdgeStrength() {
return mFadeTop ? 1.0f : 0.0f;
}
@Override
protected float getBottomFadingEdgeStrength() {
return mFadeBottom ? 1.0f : 0.0f;
}
@Override
protected float getLeftFadingEdgeStrength() {
return mFadeLeft ? 1.0f : 0.0f;
}
@Override
protected float getRightFadingEdgeStrength() {
return mFadeRight ? 1.0f : 0.0f;
}
@Override
public boolean hasOverlappingRendering() {
return true;
}
@Override
public boolean onSetAlpha(int alpha) {
return false;
}
private int getPixels(int dipValue) {
Resources r = c.getResources();
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
dipValue, r.getDisplayMetrics());
}
@Override
public void draw(Canvas canvas) {
Bitmap bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas2 = new Canvas(bitmap);
super.draw(canvas2);
canvas.drawBitmap(bitmap, 0, 0, paint2);
bitmap.recycle();
}
}
================================================
FILE: library/src/main/java/me/virtualiz/blurshadowimageview/helper/RoundImageView.java
================================================
package me.virtualiz.blurshadowimageview.helper;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.widget.ImageView;
@SuppressLint("AppCompatCustomView")
public class RoundImageView extends ImageView {
private Paint paint;
private int roundWidth = 0;
private int roundHeight = 0;
private Paint paint2;
public RoundImageView(Context context) {
this(context, null);
}
public RoundImageView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public RoundImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context);
}
private void init(Context context) {
paint = new Paint();
paint.setColor(Color.WHITE);
paint.setAntiAlias(true);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
paint2 = new Paint();
paint2.setXfermode(null);
}
public void setRound(int round_) {
if(round_ > getWidth()/2 || round_ > getHeight()/2){
if(getWidth() > getHeight()){
round_ = getHeight()/2;
}else{
round_ = getWidth()/2;
}
}
this.roundHeight = round_;
this.roundWidth = round_;
invalidate();
}
@Override
public void draw(Canvas canvas) {
Bitmap bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas2 = new Canvas(bitmap);
super.draw(canvas2);
drawLiftUp(canvas2);
drawLiftDown(canvas2);
drawRightUp(canvas2);
drawRightDown(canvas2);
canvas.drawBitmap(bitmap, 0, 0, paint2);
bitmap.recycle();
}
private void drawLiftUp(Canvas canvas) {
Path path = new Path();
path.moveTo(0, roundHeight);
path.lineTo(0, 0);
path.lineTo(roundWidth, 0);
path.arcTo(new RectF(0, 0, roundWidth * 2, roundHeight * 2), -90, -90);
path.close();
canvas.drawPath(path, paint);
}
private void drawLiftDown(Canvas canvas) {
Path path = new Path();
path.moveTo(0, getHeight() - roundHeight);
path.lineTo(0, getHeight());
path.lineTo(roundWidth, getHeight());
path.arcTo(new RectF(0, getHeight() - roundHeight * 2, roundWidth * 2, getHeight()), 90, 90);
path.close();
canvas.drawPath(path, paint);
}
private void drawRightDown(Canvas canvas) {
Path path = new Path();
path.moveTo(getWidth() - roundWidth, getHeight());
path.lineTo(getWidth(), getHeight());
path.lineTo(getWidth(), getHeight() - roundHeight);
path.arcTo(new RectF(getWidth() - roundWidth * 2, getHeight() - roundHeight * 2, getWidth(), getHeight()), -0, 90);
path.close();
canvas.drawPath(path, paint);
}
private void drawRightUp(Canvas canvas) {
Path path = new Path();
path.moveTo(getWidth(), roundHeight);
path.lineTo(getWidth(), 0);
path.lineTo(getWidth() - roundWidth, 0);
path.arcTo(new RectF(getWidth() - roundWidth * 2, 0, getWidth(), 0 + roundHeight * 2), -90, 90);
path.close();
canvas.drawPath(path, paint);
}
}
================================================
FILE: library/src/main/res/values/attr.xml
================================================
================================================
FILE: library/src/main/res/values/strings.xml
================================================
BlurShadowImageView
================================================
FILE: library/src/test/java/me/virtualiz/blurshadowimageview/ExampleUnitTest.java
================================================
package me.virtualiz.blurshadowimageview;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see Testing documentation
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
================================================
FILE: local.properties
================================================
## This file is automatically generated by Android Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file should *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
sdk.dir=C\:\\Users\\V\\AppData\\Local\\Android\\Sdk
================================================
FILE: settings.gradle
================================================
include ':app', ':library'