Hi all,
Actually i have done for scaling image on multi touch...
but the thing is after scaling if image is scaled more than screen size.. i
need to scroll that image vertically and horizontally..but on horizontal
fling i have another requirement to show next screen..
i will show my code here please suggest me the best way to achieve this
public class FadeInOutImage extends Activity implements OnTouchListener {
Animation myFadeInAnimation;
Animation myFadeOutAnimation;
ImageView imageOne, imageTwo;
boolean flag = false;
Bitmap bitmap1, bitmap2;
float scaleWidth, scaleHeight;
Matrix matrix;
// private static final Float[] floatScale = { 0.5F, 1F, 1.5F, 2F, 2.5F, 3F,
// 3.5F, 4F, 4.5F, 5F };
private float curScale = 1F;
public float zoom = 1F;
float oldDist = 0.0F;
int avflag = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fullimage);
imageOne = (ImageView) findViewById(R.id.fullImage1);
bitmap1 = BitmapFactory.decodeResource(getResources(),
R.drawable.sample_1);
int width = bitmap1.getWidth();
int height = bitmap1.getHeight();
System.out.println("width and height.." + width + " x " + height);
int newWidth = 640;
int newHeight = 480;
scaleWidth = ((float) newWidth) / width;
scaleHeight = ((float) newHeight) / height;
matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// Bitmap resizedBitmap = Bitmap.createBitmap(bitmap1, 0, 0, width,
// height, matrix, true);
// BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
imageOne.setImageBitmap(bitmap1);
imageOne.setOnTouchListener(this);
imageTwo = (ImageView) findViewById(R.id.fullImage2);
imageTwo.setOnTouchListener(this);
myFadeInAnimation = AnimationUtils.loadAnimation(this,
R.anim.fadeinfile);
myFadeOutAnimation = AnimationUtils
.loadAnimation(this, R.anim.fade_out);
// Animation mySome = AnimationUtils.loadAnimation(this,
// R.anim.slide_right);
// imageTwo.setAnimation(myFadeOutAnimation);
// // imageTwo.startAnimation(myFadeInAnimation);
// imageTwo.setAnimation(myFadeInAnimation);
// imageOne.setAnimation(myFadeInAnimation);
// imageOne.setAnimation(myFadeOutAnimation);
// imageOne.setAnimation(mySome);
Button bn = (Button) findViewById(R.id.press);
bn.setVisibility(4);
imageOne.setClickable(true);
}
void SetImageMatrix() {
Matrix mtrx = new Matrix();
curScale = (float) (zoom + 0.2);
mtrx.postScale(curScale, curScale);
// mtrx.postScale(scaleWidth, scaleHeight);
imageOne.setImageMatrix(mtrx);
imageOne.setScaleType(ScaleType.MATRIX);
imageOne.invalidate();
}
private void drawMatrix() {
if (zoom < 1)
zoom = 1;
if (zoom >= 4)
zoom = 4;
// SetImageMatrix();
System.out.println(" zoom iz " + zoom);
Matrix matrix = new Matrix();
curScale = zoom;
;
matrix.postScale(curScale, curScale);
int width = bitmap1.getWidth();
int height = bitmap1.getHeight();
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap1, 0, 0, width,
height, matrix, true);
imageOne.setImageBitmap(resizedBitmap);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
return dumpEvent(event);
// return false;
}
/** Show an event in the LogCat view, for debugging */
private boolean dumpEvent(MotionEvent event) {
String names[] = { "DOWN" , "UP" , "MOVE" , "CANCEL" , "OUTSIDE" ,
"POINTER_DOWN" , "POINTER_UP" , "7?" , "8?" , "9?" };
StringBuilder sb = new StringBuilder();
int action = event.getAction();
int actionCode = action & MotionEvent.ACTION_MASK;
sb.append("event ACTION_" ).append(names[actionCode]);
if (actionCode == MotionEvent.ACTION_POINTER_DOWN
|| actionCode == MotionEvent.ACTION_POINTER_UP) {
sb.append("(pid " ).append(
action >> MotionEvent.ACTION_POINTER_ID_SHIFT);
sb.append(")" );
}
sb.append("[" );
for (int i = 0; i < event.getPointerCount(); i++) {
sb.append("#" ).append(i);
sb.append("(pid " ).append(event.getPointerId(i));
sb.append(")=" ).append((int) event.getX(i));
sb.append("," ).append((int) event.getY(i));
if (i + 1 < event.getPointerCount())
sb.append(";" );
}
sb.append("]" );
Log.d("Ping...", sb.toString());
float currDist = spacing(event);
if (event.getPointerCount() >= 2) {
// if (3 < Math.abs(oldDist - currDist)) {
if (currDist < oldDist) {
drawMatrix();
zoom -= 0.2;
} else if (currDist > oldDist) {
drawMatrix();
zoom += 0.2;
}
oldDist = currDist;
// }
return false;
}
return false;
}
private float spacing(MotionEvent event) {
float x = event.getX(0) - event.getX(1);
float y = event.getY(0) - event.getY(1);
return FloatMath.sqrt(x * x + y * y);
}
}
please help me..
####################this code in activity.##########################
@Override
public boolean onTouch(View v, MotionEvent event) {
if (imageGesture.onTouchEvent(event)) {
return true;
}
return false;
}
class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) {
return false;
}
// right to left swipe
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
Toast.makeText(context, "Left Swipe", Toast.LENGTH_SHORT)
.show();
swip.leftSwip();
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
Toast.makeText(context, "Right Swipe", Toast.LENGTH_SHORT)
.show();
swip.rightSwip();
}
} catch (Exception e) {
// nothing
}
return true;
}
}
####################this code in activity.##########################
On Mon, Mar 14, 2011 at 6:10 PM, TreKing <[email protected]> wrote:
> On Mon, Mar 14, 2011 at 2:46 AM, leela <[email protected]> wrote:
>
>> So please tell me how to make my ImageView also supports multitouch..
>
>
> Please tell us what you have done so far and where exactly you're stuck.
>
>
> -------------------------------------------------------------------------------------------------
> TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
> transit tracking app for Android-powered devices
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
--
Thanks & Regards,
Leela Krishna m
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en