mirror of
https://github.com/wasabeef/glide-transformations.git
synced 2025-10-04 18:03:21 +08:00
For Glide 4.5.0 (#112)
This commit is contained in:
@@ -2,7 +2,7 @@ package jp.wasabeef.example.glide;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -15,7 +15,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
|
||||
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
|
||||
List<Type> dataSet = new ArrayList<>();
|
||||
dataSet.add(Type.Mask);
|
||||
|
@@ -1,11 +1,9 @@
|
||||
package jp.wasabeef.example.glide;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PointF;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -14,7 +12,6 @@ import android.widget.TextView;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.MultiTransformation;
|
||||
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import java.util.List;
|
||||
import jp.wasabeef.glide.transformations.BlurTransformation;
|
||||
import jp.wasabeef.glide.transformations.ColorFilterTransformation;
|
||||
@@ -37,7 +34,6 @@ import jp.wasabeef.glide.transformations.gpu.ToonFilterTransformation;
|
||||
import jp.wasabeef.glide.transformations.gpu.VignetteFilterTransformation;
|
||||
|
||||
import static com.bumptech.glide.request.RequestOptions.bitmapTransform;
|
||||
import static com.bumptech.glide.request.RequestOptions.centerCropTransform;
|
||||
import static com.bumptech.glide.request.RequestOptions.overrideOf;
|
||||
|
||||
/**
|
||||
@@ -83,25 +79,26 @@ public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {
|
||||
}
|
||||
|
||||
@Override public void onBindViewHolder(MainAdapter.ViewHolder holder, int position) {
|
||||
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
||||
switch (dataSet.get(position)) {
|
||||
case Mask: {
|
||||
int width = Utils.dip2px(context, 133.33f);
|
||||
int height = Utils.dip2px(context, 126.33f);
|
||||
int width = Utils.dip2px(context, 266.66f);
|
||||
int height = Utils.dip2px(context, 252.66f);
|
||||
Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.apply(overrideOf(width, height))
|
||||
.apply(bitmapTransform(new MultiTransformation<>(new CenterCrop(), new MaskTransformation(R.drawable.mask_starfish))))
|
||||
.apply(bitmapTransform(new MultiTransformation<>(new CenterCrop(),
|
||||
new MaskTransformation(R.drawable.mask_starfish))))
|
||||
.into(holder.image);
|
||||
break;
|
||||
}
|
||||
case NinePatchMask: {
|
||||
int width = Utils.dip2px(context, 150.0f);
|
||||
int height = Utils.dip2px(context, 100.0f);
|
||||
int width = Utils.dip2px(context, 300.0f);
|
||||
int height = Utils.dip2px(context, 200.0f);
|
||||
Glide.with(context)
|
||||
.load(R.drawable.check)
|
||||
.apply(overrideOf(width, height))
|
||||
.apply(bitmapTransform(new MultiTransformation<>(new CenterCrop(), new MaskTransformation(R.drawable.mask_chat_right))))
|
||||
.apply(bitmapTransform(new MultiTransformation<>(new CenterCrop(),
|
||||
new MaskTransformation(R.drawable.mask_chat_right))))
|
||||
.into(holder.image);
|
||||
break;
|
||||
}
|
||||
@@ -117,7 +114,7 @@ public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {
|
||||
Glide.with(context)
|
||||
.load(R.drawable.demo)
|
||||
.apply(bitmapTransform(
|
||||
new CropTransformation(Utils.dip2px(context, 300), Utils.dip2px(context, 100))))
|
||||
new CropTransformation(Utils.dip2px(context, 300), Utils.dip2px(context, 100), CropType.CENTER)))
|
||||
.into(holder.image);
|
||||
break;
|
||||
case CropBottom:
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package jp.wasabeef.example.glide;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2017 Wasabeef
|
||||
* Copyright (C) 2018 Wasabeef
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@@ -1,15 +1,23 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.constraint.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#CC000000"
|
||||
tools:context=".MainActivity"
|
||||
>
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
|
@@ -1,26 +1,37 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<android.support.constraint.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="5dp"
|
||||
>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:contentDescription="@null"
|
||||
android:layout_width="250dp"
|
||||
android:layout_height="250dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:cropToPadding="false"
|
||||
android:scaleType="fitCenter"
|
||||
app:layout_constraintBottom_toTopOf="@+id/title"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/image"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="5dp"
|
||||
android:textColor="@android:color/white"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:text="title"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
|
6
example/src/main/res/values/colors.xml
Normal file
6
example/src/main/res/values/colors.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="colorPrimary">#3F51B5</color>
|
||||
<color name="colorPrimaryDark">#303F9F</color>
|
||||
<color name="colorAccent">#FF4081</color>
|
||||
</resources>
|
@@ -3,6 +3,9 @@
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
</resources>
|
Reference in New Issue
Block a user