Created
September 7, 2017 16:49
-
-
Save briansalvattore/619bf7d8351bfa09f5730e97aaabe34c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.horses.mediabrands.hipoapp.ui.task; | |
import android.annotation.SuppressLint; | |
import android.content.Context; | |
import android.graphics.Bitmap; | |
import android.os.AsyncTask; | |
import android.util.Log; | |
import android.view.View; | |
import android.widget.FrameLayout; | |
import android.widget.ImageView; | |
import android.widget.LinearLayout; | |
import android.widget.RelativeLayout; | |
import com.horses.mediabrands.hipoapp.R; | |
import com.horses.mediabrands.hipoapp.util.FilterHelper; | |
import com.horses.mediabrands.hipoapp.util.Methods; | |
import org.insta.InstaFilter; | |
import jp.co.cyberagent.android.gpuimage.GPUImage; | |
import jp.co.cyberagent.android.gpuimage.GPUImageView; | |
@SuppressLint("StaticFieldLeak") | |
public class FilterImageTask extends AsyncTask<Integer, Void, Bitmap> { | |
private static final String TAG = FilterImageTask.class.getSimpleName(); | |
private View progress; | |
private FrameLayout parent; | |
private Context context; | |
private GPUImageView preview; | |
private ImageView icon; | |
private Bitmap thumbnail; | |
public FilterImageTask(Context context, LinearLayout item, Bitmap thumbnail) { | |
Log.d(TAG, "FilterImageTask() called"); | |
this.context = context; | |
this.thumbnail = thumbnail; | |
progress = item.findViewById(R.id.progress); | |
icon = item.findViewById(R.id.icon); | |
parent = item.findViewById(R.id.frame); | |
final FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(thumbnail.getWidth(), thumbnail.getHeight()); | |
preview = new GPUImageView(context); | |
preview.setLayoutParams(params); | |
//parent.addView(preview); | |
parent.addView(preview, 0); | |
} | |
@Override | |
protected void onPreExecute() { | |
Log.d(TAG, "onPreExecute() called"); | |
progress.setVisibility(View.VISIBLE); | |
} | |
@Override | |
protected Bitmap doInBackground(Integer... integers) { | |
Log.d(TAG, "doInBackground() begin with: integers = [" + integers[0] + "]"); | |
final InstaFilter filter = FilterHelper.getFilter(context, integers[0]); | |
final String name = Methods.properCase(context.getString(FilterHelper.getFilterTitle(integers[0]))); | |
Log.d(TAG, "doInBackground() called with: name = [" + name + "]"); | |
preview.setScaleType(GPUImage.ScaleType.CENTER_INSIDE); | |
preview.setImage(thumbnail); | |
preview.setFilter(filter); | |
Log.d(TAG, "doInBackground() end with: integers = [" + integers[0] + "]"); | |
try { | |
return preview.capture(); | |
} | |
catch (Exception e) { | |
Log.wtf(TAG, "doInBackground: " + name, e); | |
return null; | |
} | |
} | |
@Override | |
protected void onPostExecute(Bitmap bitmap) { | |
Log.d(TAG, "onPostExecute() called with: bitmap = [" + Methods.sizeOf(bitmap != null ? bitmap : thumbnail) + "]"); | |
parent.removeView(preview); | |
icon.setImageBitmap(bitmap != null ? bitmap : thumbnail); | |
progress.setVisibility(View.GONE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment