mirror of
https://github.com/wasabeef/glide-transformations.git
synced 2025-06-08 07:24:05 +08:00
update samples
This commit is contained in:
parent
4b2d62f979
commit
53a1f6bd0f
@ -52,5 +52,6 @@ def getKeyAliasPasswordProperty() {
|
|||||||
dependencies {
|
dependencies {
|
||||||
compile project(':transformations')
|
compile project(':transformations')
|
||||||
compile 'com.android.support:appcompat-v7:+'
|
compile 'com.android.support:appcompat-v7:+'
|
||||||
|
compile 'com.android.support:recyclerview-v7:21.+'
|
||||||
compile 'com.github.bumptech.glide:glide:3.+'
|
compile 'com.github.bumptech.glide:glide:3.+'
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
package jp.wasabeef.example.glide;
|
package jp.wasabeef.example.glide;
|
||||||
|
|
||||||
import android.support.v7.app.ActionBarActivity;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.Menu;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
import android.view.MenuItem;
|
import android.support.v7.widget.GridLayoutManager;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import jp.wasabeef.example.glide.MainAdapter.Type;
|
||||||
|
|
||||||
|
|
||||||
public class MainActivity extends ActionBarActivity {
|
public class MainActivity extends ActionBarActivity {
|
||||||
@ -12,28 +17,19 @@ public class MainActivity extends ActionBarActivity {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
}
|
|
||||||
|
|
||||||
|
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
|
||||||
|
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
|
||||||
|
|
||||||
@Override
|
List<Type> dataSet = new ArrayList<>();
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
dataSet.add(Type.Crop);
|
||||||
// Inflate the menu; this adds items to the action bar if it is present.
|
dataSet.add(Type.CropSquare);
|
||||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
dataSet.add(Type.CropCircle);
|
||||||
return true;
|
dataSet.add(Type.ColorFilter);
|
||||||
}
|
dataSet.add(Type.Grayscale);
|
||||||
|
dataSet.add(Type.RoundedCorners);
|
||||||
|
dataSet.add(Type.Blur);
|
||||||
|
|
||||||
@Override
|
recyclerView.setAdapter(new MainAdapter(this, dataSet));
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
// Handle action bar item clicks here. The action bar will
|
|
||||||
// automatically handle clicks on the Home/Up button, so long
|
|
||||||
// as you specify a parent activity in AndroidManifest.xml.
|
|
||||||
int id = item.getItemId();
|
|
||||||
|
|
||||||
//noinspection SimplifiableIfStatement
|
|
||||||
if (id == R.id.action_settings) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
103
example/src/main/java/jp/wasabeef/example/glide/MainAdapter.java
Normal file
103
example/src/main/java/jp/wasabeef/example/glide/MainAdapter.java
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
package jp.wasabeef.example.glide;
|
||||||
|
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.bumptech.glide.load.Transformation;
|
||||||
|
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import jp.wasabeef.glide.transformations.BlurTransformation;
|
||||||
|
import jp.wasabeef.glide.transformations.ColorFilterTransformation;
|
||||||
|
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.RoundedCornersTransformation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Wasabeef on 2015/01/11.
|
||||||
|
*/
|
||||||
|
public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private List<Type> mDataSet;
|
||||||
|
private BitmapPool mPool;
|
||||||
|
|
||||||
|
enum Type {
|
||||||
|
Crop,
|
||||||
|
CropSquare,
|
||||||
|
CropCircle,
|
||||||
|
ColorFilter,
|
||||||
|
Grayscale,
|
||||||
|
RoundedCorners,
|
||||||
|
Blur
|
||||||
|
}
|
||||||
|
|
||||||
|
public MainAdapter(Context context, List<Type> dataSet) {
|
||||||
|
mContext = context;
|
||||||
|
mDataSet = dataSet;
|
||||||
|
mPool = Glide.get(mContext).getBitmapPool();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MainAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
|
View v = LayoutInflater.from(mContext)
|
||||||
|
.inflate(R.layout.layout_list_item, parent, false);
|
||||||
|
return new ViewHolder(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(MainAdapter.ViewHolder holder, int position) {
|
||||||
|
Transformation<Bitmap> transformation = null;
|
||||||
|
switch (mDataSet.get(position)) {
|
||||||
|
case Crop:
|
||||||
|
transformation = new CropTransformation(mPool, 300, 100);
|
||||||
|
break;
|
||||||
|
case CropSquare:
|
||||||
|
transformation = new CropSquareTransformation(mPool);
|
||||||
|
break;
|
||||||
|
case CropCircle:
|
||||||
|
transformation = new CropCircleTransformation(mPool);
|
||||||
|
break;
|
||||||
|
case ColorFilter:
|
||||||
|
transformation = new ColorFilterTransformation(mPool, Color.argb(80, 255, 0, 0));
|
||||||
|
break;
|
||||||
|
case Grayscale:
|
||||||
|
transformation = new GrayscaleTransformation(mPool);
|
||||||
|
break;
|
||||||
|
case RoundedCorners:
|
||||||
|
transformation = new RoundedCornersTransformation(mPool, 50, 0);
|
||||||
|
break;
|
||||||
|
case Blur:
|
||||||
|
transformation = new BlurTransformation(mContext, mPool, 10);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Glide.with(mContext).load(R.drawable.demo)
|
||||||
|
.bitmapTransform(transformation).into(holder.image);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return mDataSet.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
|
public ImageView image;
|
||||||
|
|
||||||
|
ViewHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
image = (ImageView) itemView.findViewById(R.id.image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,13 @@
|
|||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
|
android:layout_width="match_parent"
|
||||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
android:layout_height="match_parent"
|
||||||
android:paddingTop="@dimen/activity_vertical_margin"
|
android:background="#CC000000"
|
||||||
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
|
<android.support.v7.widget.RecyclerView
|
||||||
android:layout_height="wrap_content"/>
|
android:id="@+id/list"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"/>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
14
example/src/main/res/layout/layout_list_item.xml
Normal file
14
example/src/main/res/layout/layout_list_item.xml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:padding="5dp">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/image"
|
||||||
|
android:layout_centerInParent="true"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:contentDescription="@null"/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
Loading…
x
Reference in New Issue
Block a user