mirror of
https://github.com/wasabeef/glide-transformations.git
synced 2025-06-08 15:34:04 +08:00
update samples
This commit is contained in:
parent
4b2d62f979
commit
53a1f6bd0f
@ -52,5 +52,6 @@ def getKeyAliasPasswordProperty() {
|
||||
dependencies {
|
||||
compile project(':transformations')
|
||||
compile 'com.android.support:appcompat-v7:+'
|
||||
compile 'com.android.support:recyclerview-v7:21.+'
|
||||
compile 'com.github.bumptech.glide:glide:3.+'
|
||||
}
|
||||
|
@ -1,9 +1,14 @@
|
||||
package jp.wasabeef.example.glide;
|
||||
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
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 {
|
||||
@ -12,28 +17,19 @@ public class MainActivity extends ActionBarActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
}
|
||||
|
||||
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
|
||||
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||
return true;
|
||||
}
|
||||
List<Type> dataSet = new ArrayList<>();
|
||||
dataSet.add(Type.Crop);
|
||||
dataSet.add(Type.CropSquare);
|
||||
dataSet.add(Type.CropCircle);
|
||||
dataSet.add(Type.ColorFilter);
|
||||
dataSet.add(Type.Grayscale);
|
||||
dataSet.add(Type.RoundedCorners);
|
||||
dataSet.add(Type.Blur);
|
||||
|
||||
@Override
|
||||
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);
|
||||
recyclerView.setAdapter(new MainAdapter(this, dataSet));
|
||||
}
|
||||
}
|
||||
|
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"
|
||||
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#CC000000"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
</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