You need to give control back to the EDT so it can draw the image. The for loop needs to be in a non EDT thread.
On Apr 4, 3:01 pm, Noobs41bot <jspi...@gmail.com> wrote: > Ok so I have all the code in place to create a random degree of rotation > between a start and finish... works great... i have a progress bar that i > can pull and watch the image rotate on the screen, while i drag it... but > when i click the button, it just sits there, and then finally shows the > image at its last state... i want to see the image rotating just as i do > when i drag my finger on it? what am i doing wrong! it has to be something > simple. please help... I have tried invalidate and postinvalidate nothing... > > main.xml: > > <?xml version=*"1.0"* encoding=*"utf-8"*?> > > <LinearLayout xmlns:android=*"http://schemas.android.com/apk/res/android" > * > > android:orientation=*"vertical" > * > > android:layout_width=*"fill_parent" > * > > android:layout_height=*"fill_parent" > * > > > > <TextView > > android:layout_width=*"fill_parent" > * > > android:layout_height=*"wrap_content" > * > > android:text=*"@string/hello" > * > > /> > > <Button android:text=*"Button"* android:id=*"@+id/button1"* > android:layout_width=*"wrap_content"* android:layout_height=*"wrap_content"* > > ></Button> > > <Spinner > > android:id=*"@+id/scale" > * > > android:layout_width=*"fill_parent" > * > > android:layout_height=*"wrap_content" > * > > /> > > <SeekBar > > android:id=*"@+id/rotate" > * > > android:layout_width=*"fill_parent" > * > > android:layout_height=*"wrap_content" > * > > android:layout_margin=*"5px" > * > > android:max=*"360" > * > > android:progress=*"0" > * > > /> > > <ImageView > > android:id=*"@+id/imageview" > * > > android:layout_gravity=*"center" > * > > android:layout_width=*"fill_parent" > * > > android:layout_height=*"fill_parent" > * > > android:scaleType=*"center" > * > > /> > > </LinearLayout> > > Main file: > > package com.exercise.AndroidBitmap; > > import java.util.Random; > > import android.app.Activity; > import android.app.AlertDialog; > import android.graphics.Bitmap; > import android.graphics.BitmapFactory; > import android.graphics.Matrix; > import android.os.Bundle; > import android.util.Log; > import android.view.View; > import android.widget.AdapterView; > import android.widget.ArrayAdapter; > import android.widget.Button; > import android.widget.ImageView; > import android.widget.SeekBar; > import android.widget.Spinner; > > public class AndroidBitmap extends Activity { > > //private final String imageInSD = "/sdcard/er.PNG"; > > ImageView myImageView; > Spinner spinnerScale; > SeekBar seekbarRotate; > > private static final String[] strScale > = {"0.2x", "0.5x", "1.0x", "2.0x", "5.0x"}; > private static final Float[] floatScale > = {0.2F, 0.5F, 1F, 2F, 5F}; > private final int defaultSpinnerScaleSelection = 2; > > private ArrayAdapter<String> adapterScale; > > private float curScale = 1F; > private float curRotate = 0F; > > //spinning variables > private static int ROTATETO; > private int START = 720; > private int END = 1440; > Random random = new Random(); > > Bitmap bitmap; > int bmpWidth, bmpHeight; > > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > final Button button = (Button) findViewById(R.id.button1); > myImageView = (ImageView)findViewById(R.id.imageview); > > spinnerScale = (Spinner)findViewById(R.id.scale); > seekbarRotate = (SeekBar)findViewById(R.id.rotate); > > adapterScale = new ArrayAdapter<String>(this, > android.R.layout.simple_spinner_item, strScale); > > adapterScale.setDropDownViewResource(android.R.layout.simple_spinner_dropdo > wn_item); > spinnerScale.setAdapter(adapterScale); > spinnerScale.setSelection(defaultSpinnerScaleSelection); > curScale = floatScale[defaultSpinnerScaleSelection]; > > // bitmap = BitmapFactory.decodeFile(imageInSD); > bitmap = BitmapFactory.decodeResource(getResources(), > R.drawable.icon); > bmpWidth = bitmap.getWidth(); > bmpHeight = bitmap.getHeight(); > > drawMatrix(); > > spinnerScale.setOnItemSelectedListener(spinnerScaleOnItemSelectedListener); > > seekbarRotate.setOnSeekBarChangeListener(seekbarRotateSeekBarChangeListener ); > > button.setOnClickListener(new View.OnClickListener() { > public void onClick(View v) > { > //AlertDialog.Builder builder = new > AlertDialog.Builder(AndroidBitmap.this); > //builder.setMessage("hi"); > ///AlertDialog alert = builder.create(); > //alert.show(); > > RandomInteger(START, END, random); > Log.d("up", Integer.toString(ROTATETO) ); > for (int i = 0; i < ROTATETO; i++) > { > curRotate = (float)i; > drawMatrix(); > //myImageView.postInvalidate(); > } > } > }); > > } > > private void drawMatrix(){ > > Matrix matrix = new Matrix(); > matrix.postScale(curScale, curScale); > matrix.postRotate(curRotate); > > Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bmpWidth, > bmpHeight, matrix, true); > myImageView.setImageBitmap(resizedBitmap); > myImageView.postInvalidate(); > > } > > private SeekBar.OnSeekBarChangeListener > seekbarRotateSeekBarChangeListener > = new SeekBar.OnSeekBarChangeListener(){ > > @Override > public void onProgressChanged(SeekBar seekBar, int progress, > boolean fromUser) { > // TODO Auto-generated method stub > curRotate = (float)progress; > drawMatrix(); > } > > @Override > public void onStartTrackingTouch(SeekBar seekBar) { > // TODO Auto-generated method stub > > } > > @Override > public void onStopTrackingTouch(SeekBar seekBar) { > // TODO Auto-generated method stub > > }}; > > private Spinner.OnItemSelectedListener spinnerScaleOnItemSelectedListener > = new Spinner.OnItemSelectedListener(){ > > @Override > public void onItemSelected(AdapterView<?> arg0, View arg1, > int arg2, long arg3) { > // TODO Auto-generated method stub > curScale = floatScale[arg2]; > drawMatrix(); > } > > @Override > public void onNothingSelected(AdapterView<?> arg0) { > // TODO Auto-generated method stub > spinnerScale.setSelection(defaultSpinnerScaleSelection); > curScale = floatScale[defaultSpinnerScaleSelection]; > }}; > > private static void RandomInteger(int aStart, int aEnd, Random aRandom){ > if ( aStart > aEnd ) > { > //throw new IllegalArgumentException("Start cannot exceed End."); > } > //get the range, casting to long to avoid overflow problems > long range = (long)aEnd - (long)aStart + 1; > // compute a fraction of the range, 0 <= frac < range > long fraction = (long)(range * aRandom.nextDouble()); > ROTATETO = (int)(fraction + aStart); > } > > > > > > > > } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en