Note that there are some explanatory texts on larger screens.

plurals
  1. POhelp with AsyncTask
    text
    copied!<p>Hi all i have the following files that make up my app. The activity has a custom view called TouchView which uses an imageprocessing class filters. Filters is process heavy so i'd like to implement AsyncTask so not to lock up the UI. I'm not sure where to start with this. could anyoune give me a high level view on how to implement this? eg which class do i extend the asynctask. The app places a fisheye effect on the bitmap. the level of distortion changes as the user moves the slidebar. Thanks mat</p> <pre><code>public class Jjilapp extends Activity { private Button b1; private static final String TAG = "*********jjil"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.e(TAG, "***********inside oncreate about to set contentview = "); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.touchview); final TouchView touchView = (TouchView)findViewById(R.id.touchview); final HorizontalSlider slider = (HorizontalSlider)findViewById(R.id.slider); touchView.initSlider(slider); }//end of oncreate } </code></pre> <p>.</p> <pre><code>public class TouchView extends View{ private File tempFile; private byte[] imageArray; private Bitmap bgr; private Bitmap bm; private Bitmap bgr2 = null;; private Paint pTouch; private int centreX = 1; private int centreY = 1; private int radius = 50; private int Progress = 1; private static final String TAG = "*********TouchView"; private Filters f = null; public TouchView(Context context) { super(context); // TouchView(context, null); } public TouchView(Context context, AttributeSet attr) { super(context,attr); //code to get image from camera and sdcard bgr2 = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), bm.getConfig()); f = new Filters(); }// end of touchView constructor public void findCirclePixels(){ float prog = (float)Progress/150000; bgr2 = f.barrel(bgr,prog); }// end of changePixel() public void initSlider(final HorizontalSlider slider) { Log.e(TAG, "******setting up slider*********** "); slider.setOnProgressChangeListener(changeListener); } private OnProgressChangeListener changeListener = new OnProgressChangeListener() { @Override public void onProgressChanged(View v, int progress) { // TODO Auto-generated method stub setProgress(progress); Log.e(TAG, "***********progress = "+Progress); } }; @Override public void onDraw(Canvas canvas){ super.onDraw(canvas); canvas.drawBitmap(bgr2, 0, 0, null); }//end of onDraw protected void setProgress(int progress2) { this.Progress = progress2; findCirclePixels(); invalidate(); } } </code></pre> <p>.</p> <pre><code>class Filters{ float xscale; float yscale; float xshift; float yshift; int [] s; private String TAG = "Filters"; public Filters(){ Log.e(TAG, "***********inside constructor"); } public Bitmap barrel (Bitmap input, float k){ // code that places effect on bitmap } }// end of filters class </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload