1
0
mirror of https://github.com/wasabeef/glide-transformations.git synced 2025-10-04 18:03:21 +08:00

change the codestyle

This commit is contained in:
wasabeef
2015-09-06 01:24:12 +09:00
parent cdbd42595a
commit f83e5ef85a
26 changed files with 906 additions and 956 deletions

View File

@@ -1,21 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="jp.wasabeef.example.glide" >
package="jp.wasabeef.example.glide"
>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>

View File

@@ -4,44 +4,40 @@ import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
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 AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@Override 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));
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
List<Type> dataSet = new ArrayList<>();
dataSet.add(Type.CropTop);
dataSet.add(Type.CropCenter);
dataSet.add(Type.CropBottom);
dataSet.add(Type.CropSquare);
dataSet.add(Type.CropCircle);
dataSet.add(Type.ColorFilter);
dataSet.add(Type.Grayscale);
dataSet.add(Type.RoundedCorners);
dataSet.add(Type.Blur);
dataSet.add(Type.Toon);
dataSet.add(Type.Sepia);
dataSet.add(Type.Contrast);
dataSet.add(Type.Invert);
dataSet.add(Type.Pixel);
dataSet.add(Type.Sketch);
dataSet.add(Type.Swirl);
dataSet.add(Type.Brightness);
dataSet.add(Type.Kuawahara);
dataSet.add(Type.Vignette);
List<Type> dataSet = new ArrayList<>();
dataSet.add(Type.CropTop);
dataSet.add(Type.CropCenter);
dataSet.add(Type.CropBottom);
dataSet.add(Type.CropSquare);
dataSet.add(Type.CropCircle);
dataSet.add(Type.ColorFilter);
dataSet.add(Type.Grayscale);
dataSet.add(Type.RoundedCorners);
dataSet.add(Type.Blur);
dataSet.add(Type.Toon);
dataSet.add(Type.Sepia);
dataSet.add(Type.Contrast);
dataSet.add(Type.Invert);
dataSet.add(Type.Pixel);
dataSet.add(Type.Sketch);
dataSet.add(Type.Swirl);
dataSet.add(Type.Brightness);
dataSet.add(Type.Kuawahara);
dataSet.add(Type.Vignette);
recyclerView.setAdapter(new MainAdapter(this, dataSet));
}
recyclerView.setAdapter(new MainAdapter(this, dataSet));
}
}

View File

@@ -1,8 +1,5 @@
package jp.wasabeef.example.glide;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import android.content.Context;
import android.graphics.Color;
import android.graphics.PointF;
@@ -12,9 +9,9 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import java.util.List;
import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.ColorFilterTransformation;
import jp.wasabeef.glide.transformations.CropCircleTransformation;
@@ -38,130 +35,124 @@ import jp.wasabeef.glide.transformations.gpu.VignetteFilterTransformation;
*/
public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {
private Context mContext;
private List<Type> mDataSet;
private Context mContext;
private List<Type> mDataSet;
enum Type {
CropTop,
CropCenter,
CropBottom,
CropSquare,
CropCircle,
ColorFilter,
Grayscale,
RoundedCorners,
Blur,
Toon,
Sepia,
Contrast,
Invert,
Pixel,
Sketch,
Swirl,
Brightness,
Kuawahara,
Vignette
enum Type {
CropTop,
CropCenter,
CropBottom,
CropSquare,
CropCircle,
ColorFilter,
Grayscale,
RoundedCorners,
Blur,
Toon,
Sepia,
Contrast,
Invert,
Pixel,
Sketch,
Swirl,
Brightness,
Kuawahara,
Vignette
}
public MainAdapter(Context context, List<Type> dataSet) {
mContext = context;
mDataSet = dataSet;
}
@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 transformation = null;
switch (mDataSet.get(position)) {
case CropTop:
transformation =
new CropTransformation(mContext, 300, 100, CropTransformation.CropType.TOP);
break;
case CropCenter:
transformation = new CropTransformation(mContext, 300, 100);
break;
case CropBottom:
transformation =
new CropTransformation(mContext, 300, 100, CropTransformation.CropType.BOTTOM);
break;
case CropSquare:
transformation = new CropSquareTransformation(mContext);
break;
case CropCircle:
transformation = new CropCircleTransformation(mContext);
break;
case ColorFilter:
transformation = new ColorFilterTransformation(mContext, Color.argb(80, 255, 0, 0));
break;
case Grayscale:
transformation = new GrayscaleTransformation(mContext);
break;
case RoundedCorners:
transformation = new RoundedCornersTransformation(mContext, 100, 0);
break;
case Blur:
transformation = new BlurTransformation(mContext, 25, 1);
break;
case Toon:
transformation = new ToonFilterTransformation(mContext);
break;
case Sepia:
transformation = new SepiaFilterTransformation(mContext);
break;
case Contrast:
transformation = new ContrastFilterTransformation(mContext, 2.0f);
break;
case Invert:
transformation = new InvertFilterTransformation(mContext);
break;
case Pixel:
transformation = new PixelationFilterTransformation(mContext, 20);
break;
case Sketch:
transformation = new SketchFilterTransformation(mContext);
break;
case Swirl:
transformation =
new SwirlFilterTransformation(mContext, 0.5f, 1.0f, new PointF(0.5f, 0.5f));
break;
case Brightness:
transformation = new BrightnessFilterTransformation(mContext, 0.5f);
break;
case Kuawahara:
transformation = new KuwaharaFilterTransformation(mContext, 25);
break;
case Vignette:
transformation = new VignetteFilterTransformation(mContext, new PointF(0.5f, 0.5f),
new float[] { 0.0f, 0.0f, 0.0f }, 0f, 0.75f);
break;
}
public MainAdapter(Context context, List<Type> dataSet) {
mContext = context;
mDataSet = dataSet;
}
@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 transformation = null;
switch (mDataSet.get(position)) {
case CropTop:
transformation =
new CropTransformation(mContext, 300, 100, CropTransformation.CropType.TOP);
break;
case CropCenter:
transformation = new CropTransformation(mContext, 300, 100);
break;
case CropBottom:
transformation =
new CropTransformation(mContext, 300, 100,
CropTransformation.CropType.BOTTOM);
break;
case CropSquare:
transformation = new CropSquareTransformation(mContext);
break;
case CropCircle:
transformation = new CropCircleTransformation(mContext);
break;
case ColorFilter:
transformation = new ColorFilterTransformation(mContext, Color.argb(80, 255, 0, 0));
break;
case Grayscale:
transformation = new GrayscaleTransformation(mContext);
break;
case RoundedCorners:
transformation = new RoundedCornersTransformation(mContext, 100, 0);
break;
case Blur:
transformation = new BlurTransformation(mContext, 25, 1);
break;
case Toon:
transformation = new ToonFilterTransformation(mContext);
break;
case Sepia:
transformation = new SepiaFilterTransformation(mContext);
break;
case Contrast:
transformation = new ContrastFilterTransformation(mContext, 2.0f);
break;
case Invert:
transformation = new InvertFilterTransformation(mContext);
break;
case Pixel:
transformation = new PixelationFilterTransformation(mContext, 20);
break;
case Sketch:
transformation = new SketchFilterTransformation(mContext);
break;
case Swirl:
transformation = new SwirlFilterTransformation(mContext,
0.5f, 1.0f, new PointF(0.5f, 0.5f));
break;
case Brightness:
transformation = new BrightnessFilterTransformation(mContext, 0.5f);
break;
case Kuawahara:
transformation = new KuwaharaFilterTransformation(mContext, 25);
break;
case Vignette:
transformation = new VignetteFilterTransformation(mContext,
new PointF(0.5f, 0.5f), new float[]{0.0f, 0.0f, 0.0f}, 0f, 0.75f);
break;
}
Glide.with(mContext).load(R.drawable.demo)
.bitmapTransform(transformation).into(holder.image);
holder.title.setText(mDataSet.get(position).name());
}
@Override
public int getItemCount() {
return mDataSet.size();
}
static class ViewHolder extends RecyclerView.ViewHolder {
public ImageView image;
public TextView title;
ViewHolder(View itemView) {
super(itemView);
image = (ImageView) itemView.findViewById(R.id.image);
title = (TextView) itemView.findViewById(R.id.title);
}
Glide.with(mContext).load(R.drawable.demo).bitmapTransform(transformation).into(holder.image);
holder.title.setText(mDataSet.get(position).name());
}
@Override public int getItemCount() {
return mDataSet.size();
}
static class ViewHolder extends RecyclerView.ViewHolder {
public ImageView image;
public TextView title;
ViewHolder(View itemView) {
super(itemView);
image = (ImageView) itemView.findViewById(R.id.image);
title = (TextView) itemView.findViewById(R.id.title);
}
}
}

View File

@@ -1,13 +1,15 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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:background="#CC000000"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
/>
</RelativeLayout>

View File

@@ -1,23 +1,26 @@
<?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_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp">
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:contentDescription="@null"
/>
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:contentDescription="@null"/>
<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"/>
<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"
/>
</RelativeLayout>

View File

@@ -1,6 +1,6 @@
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>

View File

@@ -1,5 +1,5 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">glide-transformations</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="app_name">glide-transformations</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
</resources>

View File

@@ -1,8 +1,8 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>