mirror of
https://github.com/wasabeef/glide-transformations.git
synced 2025-10-05 02:13:22 +08:00
Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
4629d5e375 | ||
|
113200de55 | ||
|
143efe2ea7 | ||
|
fe864e498b | ||
|
f2f1229c8d | ||
|
f1246ff9ee | ||
|
d063aac6fa | ||
|
cb3cd88ed2 | ||
|
57fcfce9df | ||
|
347326dafa | ||
|
b4332f8c8d | ||
|
39b9d6aa6b | ||
|
2c08c1fb5e | ||
|
abde4c694d | ||
|
d5616ec9fa | ||
|
1253147c4a | ||
|
7614f1326a | ||
|
5cf3e3d934 | ||
|
efc447d2f7 | ||
|
23b623c882 | ||
|
f9ea19aaae | ||
|
831f038d29 | ||
|
eed7b944e5 | ||
|
46d5d4d72f | ||
|
6ebfdbe581 | ||
|
2a4eb22841 |
13
CHANGELOG.md
13
CHANGELOG.md
@@ -1,7 +1,18 @@
|
||||
Change Log
|
||||
==========
|
||||
|
||||
Version 1.1.0 *(2015-07-24)*
|
||||
Version 1.2.1 *(2015-09-18)*
|
||||
----------------------------
|
||||
|
||||
Merged NinePatchMaskTransformation to MaskTransformation.
|
||||
|
||||
Version 1.2.0 *(2015-09-16)*
|
||||
----------------------------
|
||||
|
||||
add new transformations MaskTransformation and NinePatchMaskTransformation.
|
||||
Thanks to [start141](https://github.com/start141)
|
||||
|
||||
Version 1.1.0 *(2015-09-05)*
|
||||
----------------------------
|
||||
|
||||
Adjustment of default parameters.
|
||||
|
27
README.md
27
README.md
@@ -32,7 +32,7 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'jp.wasabeef:glide-transformations:1.1.0'
|
||||
compile 'jp.wasabeef:glide-transformations:1.2.1'
|
||||
// If you want to use the GPU Filters
|
||||
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.3.0'
|
||||
}
|
||||
@@ -54,7 +54,7 @@ You can set a multiple transformations.
|
||||
|
||||
```java
|
||||
Glide.with(this).load(R.drawable.demo)
|
||||
.bitmapTransform(new BlurTransformation(context, 25, 2), new CropCircleTransformation(pool))
|
||||
.bitmapTransform(new BlurTransformation(context, 25, 2), new CropCircleTransformation(context))
|
||||
.into((ImageView) findViewById(R.id.image));
|
||||
```
|
||||
|
||||
@@ -76,7 +76,8 @@ android {
|
||||
## Transformations
|
||||
|
||||
### Crop
|
||||
`CropTransformation`, `CropCircleTransformation`, `CropSquareTransformation`
|
||||
`CropTransformation`, `CropCircleTransformation`, `CropSquareTransformation`,
|
||||
`RoundedCornersTransformation`
|
||||
|
||||
### Color
|
||||
`ColorFilterTransformation`, `GrayscaleTransformation`
|
||||
@@ -84,14 +85,16 @@ android {
|
||||
### Blur
|
||||
`BlurTransformation`
|
||||
|
||||
### Filter (use [GPUImage](https://github.com/CyberAgent/android-gpuimage))
|
||||
### Mask
|
||||
`MaskTransformation`
|
||||
|
||||
### GPU Filter (use [GPUImage](https://github.com/CyberAgent/android-gpuimage))
|
||||
**Will require add dependencies for GPUImage.**
|
||||
|
||||
`ToonFilterTransformation`, `SepiaFilterTransformation`, `ContrastFilterTransformation`
|
||||
`InvertFilterTransformation`, `PixelationFilterTransformation`, `SketchFilterTransformation`
|
||||
`SwirlFilterTransformation`, `KuwaharaFilterTransformation`, `VignetteFilterTransformation`
|
||||
|
||||
### Other
|
||||
`RoundedCornersTransformation`
|
||||
|
||||
Applications using Glide Transformations
|
||||
---
|
||||
|
||||
@@ -110,6 +113,16 @@ Daichi Furiya (Wasabeef) - <dadadada.chop@gmail.com>
|
||||
src="https://raw.githubusercontent.com/wasabeef/art/master/twitter.png" width="75"/>
|
||||
</a>
|
||||
|
||||
Contributions
|
||||
-------
|
||||
|
||||
Any contributions are welcome!
|
||||
|
||||
Contributers
|
||||
-------
|
||||
|
||||
* [start141](https://github.com/start141)
|
||||
|
||||
Thanks
|
||||
-------
|
||||
|
||||
|
BIN
art/demo.gif
BIN
art/demo.gif
Binary file not shown.
Before Width: | Height: | Size: 9.9 MiB After Width: | Height: | Size: 3.9 MiB |
@@ -6,7 +6,7 @@ buildscript {
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:1.3.1'
|
||||
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
|
||||
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.3.1'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
|
@@ -18,6 +18,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
|
||||
|
||||
List<Type> dataSet = new ArrayList<>();
|
||||
dataSet.add(Type.Mask);
|
||||
dataSet.add(Type.NinePatchMask);
|
||||
dataSet.add(Type.CropTop);
|
||||
dataSet.add(Type.CropCenter);
|
||||
dataSet.add(Type.CropBottom);
|
||||
|
@@ -10,7 +10,7 @@ import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
|
||||
import java.util.List;
|
||||
import jp.wasabeef.glide.transformations.BlurTransformation;
|
||||
import jp.wasabeef.glide.transformations.ColorFilterTransformation;
|
||||
@@ -18,6 +18,7 @@ import jp.wasabeef.glide.transformations.CropCircleTransformation;
|
||||
import jp.wasabeef.glide.transformations.CropSquareTransformation;
|
||||
import jp.wasabeef.glide.transformations.CropTransformation;
|
||||
import jp.wasabeef.glide.transformations.GrayscaleTransformation;
|
||||
import jp.wasabeef.glide.transformations.MaskTransformation;
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||
import jp.wasabeef.glide.transformations.gpu.BrightnessFilterTransformation;
|
||||
import jp.wasabeef.glide.transformations.gpu.ContrastFilterTransformation;
|
||||
@@ -39,6 +40,8 @@ public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {
|
||||
private List<Type> mDataSet;
|
||||
|
||||
enum Type {
|
||||
Mask,
|
||||
NinePatchMask,
|
||||
CropTop,
|
||||
CropCenter,
|
||||
CropBottom,
|
||||
@@ -71,72 +74,149 @@ public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {
|
||||
}
|
||||
|
||||
@Override public void onBindViewHolder(MainAdapter.ViewHolder holder, int position) {
|
||||
Transformation transformation = null;
|
||||
switch (mDataSet.get(position)) {
|
||||
case Mask: {
|
||||
int width = Utils.dip2px(mContext, 133.33f);
|
||||
int height = Utils.dip2px(mContext, 126.33f);
|
||||
Glide.with(mContext)
|
||||
.load(R.drawable.check)
|
||||
.override(width, height)
|
||||
.bitmapTransform(new CenterCrop(mContext),
|
||||
new MaskTransformation(mContext, R.drawable.mask_starfish))
|
||||
.into(holder.image);
|
||||
break;
|
||||
}
|
||||
case NinePatchMask: {
|
||||
int width = Utils.dip2px(mContext, 150.0f);
|
||||
int height = Utils.dip2px(mContext, 100.0f);
|
||||
Glide.with(mContext)
|
||||
.load(R.drawable.check)
|
||||
.override(width, height)
|
||||
.bitmapTransform(new CenterCrop(mContext),
|
||||
new MaskTransformation(mContext, R.drawable.mask_chat_right))
|
||||
.into(holder.image);
|
||||
break;
|
||||
}
|
||||
case CropTop:
|
||||
transformation =
|
||||
new CropTransformation(mContext, 300, 100, CropTransformation.CropType.TOP);
|
||||
Glide.with(mContext)
|
||||
.load(R.drawable.demo)
|
||||
.bitmapTransform(
|
||||
new CropTransformation(mContext, 300, 100, CropTransformation.CropType.TOP))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case CropCenter:
|
||||
transformation = new CropTransformation(mContext, 300, 100);
|
||||
Glide.with(mContext)
|
||||
.load(R.drawable.demo)
|
||||
.bitmapTransform(new CropTransformation(mContext, 300, 100))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case CropBottom:
|
||||
transformation =
|
||||
new CropTransformation(mContext, 300, 100, CropTransformation.CropType.BOTTOM);
|
||||
Glide.with(mContext)
|
||||
.load(R.drawable.demo)
|
||||
.bitmapTransform(
|
||||
new CropTransformation(mContext, 300, 100, CropTransformation.CropType.BOTTOM))
|
||||
.into(holder.image);
|
||||
|
||||
break;
|
||||
case CropSquare:
|
||||
transformation = new CropSquareTransformation(mContext);
|
||||
Glide.with(mContext)
|
||||
.load(R.drawable.demo)
|
||||
.bitmapTransform(new CropSquareTransformation(mContext))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case CropCircle:
|
||||
transformation = new CropCircleTransformation(mContext);
|
||||
Glide.with(mContext)
|
||||
.load(R.drawable.demo)
|
||||
.bitmapTransform(new CropCircleTransformation(mContext))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case ColorFilter:
|
||||
transformation = new ColorFilterTransformation(mContext, Color.argb(80, 255, 0, 0));
|
||||
Glide.with(mContext)
|
||||
.load(R.drawable.demo)
|
||||
.bitmapTransform(new ColorFilterTransformation(mContext, Color.argb(80, 255, 0, 0)))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case Grayscale:
|
||||
transformation = new GrayscaleTransformation(mContext);
|
||||
Glide.with(mContext)
|
||||
.load(R.drawable.demo)
|
||||
.bitmapTransform(new GrayscaleTransformation(mContext))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case RoundedCorners:
|
||||
transformation = new RoundedCornersTransformation(mContext, 100, 0);
|
||||
Glide.with(mContext)
|
||||
.load(R.drawable.demo)
|
||||
.bitmapTransform(new RoundedCornersTransformation(mContext, 100, 0))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case Blur:
|
||||
transformation = new BlurTransformation(mContext, 25, 1);
|
||||
Glide.with(mContext)
|
||||
.load(R.drawable.check)
|
||||
.bitmapTransform(new BlurTransformation(mContext, 25, 1))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case Toon:
|
||||
transformation = new ToonFilterTransformation(mContext);
|
||||
Glide.with(mContext)
|
||||
.load(R.drawable.demo)
|
||||
.bitmapTransform(new ToonFilterTransformation(mContext))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case Sepia:
|
||||
transformation = new SepiaFilterTransformation(mContext);
|
||||
Glide.with(mContext)
|
||||
.load(R.drawable.check)
|
||||
.bitmapTransform(new SepiaFilterTransformation(mContext))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case Contrast:
|
||||
transformation = new ContrastFilterTransformation(mContext, 2.0f);
|
||||
Glide.with(mContext)
|
||||
.load(R.drawable.check)
|
||||
.bitmapTransform(new ContrastFilterTransformation(mContext, 2.0f))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case Invert:
|
||||
transformation = new InvertFilterTransformation(mContext);
|
||||
Glide.with(mContext)
|
||||
.load(R.drawable.check)
|
||||
.bitmapTransform(new InvertFilterTransformation(mContext))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case Pixel:
|
||||
transformation = new PixelationFilterTransformation(mContext, 20);
|
||||
Glide.with(mContext)
|
||||
.load(R.drawable.check)
|
||||
.bitmapTransform(new PixelationFilterTransformation(mContext, 20))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case Sketch:
|
||||
transformation = new SketchFilterTransformation(mContext);
|
||||
Glide.with(mContext)
|
||||
.load(R.drawable.check)
|
||||
.bitmapTransform(new SketchFilterTransformation(mContext))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case Swirl:
|
||||
transformation =
|
||||
new SwirlFilterTransformation(mContext, 0.5f, 1.0f, new PointF(0.5f, 0.5f));
|
||||
Glide.with(mContext)
|
||||
.load(R.drawable.check)
|
||||
.bitmapTransform(
|
||||
new SwirlFilterTransformation(mContext, 0.5f, 1.0f, new PointF(0.5f, 0.5f)))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case Brightness:
|
||||
transformation = new BrightnessFilterTransformation(mContext, 0.5f);
|
||||
Glide.with(mContext)
|
||||
.load(R.drawable.check)
|
||||
.bitmapTransform(new BrightnessFilterTransformation(mContext, 0.5f))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case Kuawahara:
|
||||
transformation = new KuwaharaFilterTransformation(mContext, 25);
|
||||
Glide.with(mContext)
|
||||
.load(R.drawable.check)
|
||||
.bitmapTransform(new KuwaharaFilterTransformation(mContext, 25))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case Vignette:
|
||||
transformation = new VignetteFilterTransformation(mContext, new PointF(0.5f, 0.5f),
|
||||
new float[] { 0.0f, 0.0f, 0.0f }, 0f, 0.75f);
|
||||
Glide.with(mContext)
|
||||
.load(R.drawable.check)
|
||||
.bitmapTransform(new VignetteFilterTransformation(mContext, new PointF(0.5f, 0.5f),
|
||||
new float[] { 0.0f, 0.0f, 0.0f }, 0f, 0.75f))
|
||||
.into(holder.image);
|
||||
break;
|
||||
}
|
||||
|
||||
Glide.with(mContext).load(R.drawable.demo).bitmapTransform(transformation).into(holder.image);
|
||||
holder.title.setText(mDataSet.get(position).name());
|
||||
}
|
||||
|
||||
|
27
example/src/main/java/jp/wasabeef/example/glide/Utils.java
Normal file
27
example/src/main/java/jp/wasabeef/example/glide/Utils.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package jp.wasabeef.example.glide;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2015 Wasabeef
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public class Utils {
|
||||
|
||||
public static int dip2px(Context context, float dp) {
|
||||
float scale = context.getResources().getDisplayMetrics().density;
|
||||
return (int) (dp * scale + 0.5f);
|
||||
}
|
||||
}
|
BIN
example/src/main/res/drawable-xhdpi/check.png
Normal file
BIN
example/src/main/res/drawable-xhdpi/check.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 484 KiB |
BIN
example/src/main/res/drawable-xxhdpi/mask_chat_right.9.png
Normal file
BIN
example/src/main/res/drawable-xxhdpi/mask_chat_right.9.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
BIN
example/src/main/res/drawable-xxhdpi/mask_starfish.png
Normal file
BIN
example/src/main/res/drawable-xxhdpi/mask_starfish.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.6 KiB |
@@ -1,5 +1,5 @@
|
||||
VERSION_NAME=1.1.0
|
||||
VERSION_CODE=9
|
||||
VERSION_NAME=1.2.1
|
||||
VERSION_CODE=11
|
||||
GROUP=jp.wasabeef
|
||||
ARTIFACT_ID=glide-transformations
|
||||
|
||||
|
@@ -16,7 +16,7 @@ android {
|
||||
|
||||
dependencies {
|
||||
compile "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
|
||||
compile "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
|
||||
provided "jp.co.cyberagent.android.gpuimage:gpuimage-library:${GPUIMAGE_VERSION}"
|
||||
}
|
||||
|
||||
android.libraryVariants.all { variant ->
|
||||
@@ -39,4 +39,4 @@ android.libraryVariants.all { variant ->
|
||||
|
||||
apply from: 'android-artifacts.gradle'
|
||||
apply from: 'central-publish.gradle'
|
||||
apply from: 'bintray-publish.gradle'
|
||||
apply from: 'bintray-publish.gradle'
|
||||
|
@@ -58,6 +58,7 @@ public class CropCircleTransformation implements Transformation<Bitmap> {
|
||||
BitmapShader shader =
|
||||
new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
|
||||
if (width != 0 || height != 0) {
|
||||
// source isn't square, move viewport to center
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.setTranslate(-width, -height);
|
||||
shader.setLocalMatrix(matrix);
|
||||
|
@@ -0,0 +1,81 @@
|
||||
package jp.wasabeef.glide.transformations;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2015 Wasabeef
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.Transformation;
|
||||
import com.bumptech.glide.load.engine.Resource;
|
||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||
import jp.wasabeef.glide.transformations.internal.Utils;
|
||||
|
||||
public class MaskTransformation implements Transformation<Bitmap> {
|
||||
|
||||
private static Paint mMaskingPaint = new Paint();
|
||||
private Context mContext;
|
||||
private BitmapPool mBitmapPool;
|
||||
private int mMaskId;
|
||||
|
||||
static {
|
||||
mMaskingPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param maskId If you change the mask file, please also rename the mask file, or Glide will get
|
||||
* the cache with the old mask. Because getId() return the same values if using the
|
||||
* same make file name. If you have a good idea please tell us, thanks.
|
||||
*/
|
||||
public MaskTransformation(Context context, int maskId) {
|
||||
mBitmapPool = Glide.get(context).getBitmapPool();
|
||||
mContext = context;
|
||||
mMaskId = maskId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
|
||||
Bitmap source = resource.get();
|
||||
|
||||
int width = source.getWidth();
|
||||
int height = source.getHeight();
|
||||
|
||||
Bitmap result = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
|
||||
if (result == null) {
|
||||
result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
}
|
||||
|
||||
Drawable mask = Utils.getMaskDrawable(mContext, mMaskId);
|
||||
|
||||
Canvas canvas = new Canvas(result);
|
||||
mask.setBounds(0, 0, width, height);
|
||||
mask.draw(canvas);
|
||||
canvas.drawBitmap(source, 0, 0, mMaskingPaint);
|
||||
|
||||
return BitmapResource.obtain(result, mBitmapPool);
|
||||
}
|
||||
|
||||
@Override public String getId() {
|
||||
return "MaskTransformation(maskId=" + mContext.getResources().getResourceEntryName(mMaskId)
|
||||
+ ")";
|
||||
}
|
||||
}
|
@@ -27,13 +27,7 @@ import jp.co.cyberagent.android.gpuimage.GPUImage;
|
||||
import jp.co.cyberagent.android.gpuimage.GPUImageKuwaharaFilter;
|
||||
|
||||
/**
|
||||
* Kuwahara image abstraction, drawn from the work of Kyprianidis, et. al. in their publication
|
||||
* "Anisotropic Kuwahara Filtering on the GPU" within the GPU Pro collection. This produces an
|
||||
* oil-painting-like
|
||||
* image, but it is extremely computationally expensive, so it can take seconds to render a frame
|
||||
* on
|
||||
* an iPad 2.
|
||||
* This might be best used for still images.
|
||||
* Kuwahara all the colors in the image.
|
||||
*
|
||||
* The radius to sample from when creating the brush-stroke effect, with a default of 25.
|
||||
* The larger the radius, the slower the filter.
|
||||
|
@@ -0,0 +1,43 @@
|
||||
package jp.wasabeef.glide.transformations.internal;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2015 Wasabeef
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
public final class Utils {
|
||||
|
||||
private Utils() {
|
||||
// Utility class.
|
||||
}
|
||||
|
||||
public static Drawable getMaskDrawable(Context context, int maskId) {
|
||||
Drawable drawable;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
drawable = context.getDrawable(maskId);
|
||||
} else {
|
||||
drawable = context.getResources().getDrawable(maskId);
|
||||
}
|
||||
|
||||
if (drawable == null) {
|
||||
throw new IllegalArgumentException("maskId is invalid");
|
||||
}
|
||||
|
||||
return drawable;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user