I'm trying to test something out, but all I need is an activity that blinks between black and white screens at an interval of 1 second. I've looked at postDelayed, but I'm still not sure how I would implement that. This is what I have right now, but it doesn't "blink"
MainActivity:
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
public class Blink extends Activity {
int i = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_blink);
while (i == 0) {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
changeColor();
}
}, 1000);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void changeColor() {
if (findViewById(R.id.mylayout).getBackground().equals("#ffffff")) {
findViewById(R.id.mylayout).setBackgroundResource(Color.BLACK);
} else {
findViewById(R.id.mylayout).setBackgroundResource(Color.WHITE);
}
}
}
Updated Code:
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
public class Blink extends Activity {
int i = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_blink);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
changeColor();
}
}, 1000);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void changeColor() {
if (i == 0) {
findViewById(R.id.mylayout).setBackgroundColor(Color.WHITE);
i++;
} else if (i == 1) {
findViewById(R.id.mylayout).setBackgroundColor(Color.BLACK);
i--;
}
}
}
Update 2:
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
public class Blink extends Activity {
int i = 0;
Boolean bool = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_blink);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
changeColor();
}
}, 1000);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void changeColor() {
if (bool) {
findViewById(R.id.mylayout).setBackgroundColor(Color.WHITE);
bool = false;
} else {
findViewById(R.id.mylayout).setBackgroundColor(Color.BLACK);
bool = true;
}
}
}
I narrowed down the exact question I should be asking right here: Why doesn't this postDelayed run forever?
To fix this code, all I had to do was add handler.postDelayed(this, 1000); inside of run.
Related
I am very new to programming and I have a problem with a game which I am trying to make.
Almost every time when I exit the game it was crashing.
After adding: if (canvas != null) beforew canvas.drawColor(Color.CYAN); it does not crash on exit anymore but when I return to the game.
Here is the code: (its not my actual game... there is nothing in OnDraw exept canvas.drawColor(Color.CYAN); that keeps it simple)
GameView.java:
package com.example.test.threadtest;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class GameView extends SurfaceView {
private GameLoopThread theGameLoopThread;
private SurfaceHolder surfaceHolder;
public GameView(Context context) {
super(context);
theGameLoopThread = new GameLoopThread(this);
surfaceHolder = getHolder();
surfaceHolder.addCallback(new SurfaceHolder.Callback() {
public void surfaceDestroyed(SurfaceHolder holder) {
boolean retry = true;
theGameLoopThread.setRunning(false);
while (retry) {
try {
theGameLoopThread.join();
retry = false;
} catch (InterruptedException e) {
}
}
}
public void surfaceCreated(SurfaceHolder holder) {
theGameLoopThread.setRunning(true);
theGameLoopThread.start();
}
public void surfaceChanged(SurfaceHolder holder, int format,
int width, int height) {
// TODO Auto-generated method stub
}
});
}
#Override
protected void onDraw(Canvas canvas) {
if (canvas != null)
canvas.drawColor(Color.CYAN);
}
}
GameLoopThread.java:
package com.example.test.threadtest;
import android.annotation.SuppressLint;
import android.graphics.Canvas;
public class GameLoopThread extends Thread {
static final long FPS = 20;
private GameView theView;
private boolean isRunning = false;
public GameLoopThread(GameView theView) {
this.theView = theView;
}
public void setRunning(boolean run) {
isRunning = run;
}
#SuppressLint("WrongCall") #Override
public void run() {
long TPS = 1000 / FPS;
long startTime, sleepTime;
while (isRunning) {
Canvas theCanvas = null;
startTime = System.currentTimeMillis();
try {
theCanvas = theView.getHolder().lockCanvas();
synchronized (theView.getHolder()) {
theView.onDraw(theCanvas);
}
} finally {
if (theCanvas != null) {
theView.getHolder().unlockCanvasAndPost(theCanvas);
}
}
sleepTime = TPS - (System.currentTimeMillis() - startTime);
try {
if (sleepTime > 0)
sleep(sleepTime);
else
sleep(10);
} catch (Exception e) {
}
}
}
}
MainAcitvity.java:
package com.example.test.threadtest;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new GameView(this));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
I am trying to accept BrainTree on my app. I don't understand the Async HTTP Client part.
Where do I place this in my app? Currently, I have it in the MainActivity and it is giving me errors for 'get', 'TextHttpResponseHandler' as well as 'clientToken'.
Any ideas?
package com.example.android.payments;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import com.loopj.android.http.*;
import com.braintreepayments.api.dropin.BraintreePaymentActivity;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
AsyncHttpClient client = new AsyncHttpClient();
client.get("https://your-server/client_token", new TextHttpResponseHandler() {
#Override
public void onSuccess(String clientToken) {
this.clientToken = clientToken;
}
});
public void onBraintreeSubmit(View v) {
Intent intent = new Intent(context, BraintreePaymentActivity.class);
intent.putExtra(BraintreePaymentActivity.EXTRA_CLIENT_TOKEN, clientToken);
// REQUEST_CODE is arbitrary and is only used within this activity.
startActivityForResult(intent, REQUEST_CODE);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Your call to client.get() is not in a method body, so your code is not syntactically valid. Try putting it in a method (or constructor or initializer block - but it's a bad idea to do work in either of those places).
For example, you could put that statement in a new method called fetchClientToken():
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) { ... }
AsyncHttpClient client = new AsyncHttpClient();
public void fetchClientToken() {
client.get("https://your-server/client_token", new TextHttpResponseHandler() {
#Override
public void onSuccess(String clientToken) {
this.clientToken = clientToken;
}
});
}
public void onBraintreeSubmit(View v) { ... }
#Override public boolean onCreateOptionsMenu(Menu menu) { ... }
#Override public boolean onOptionsItemSelected(MenuItem item) { ... }
}
You then need to invoke fetchClientToken somehow, just like you would with any other method.
I've created 2 separate projects in Android from tutorials etc., - one which runs an animation of an horse running, and the other a scrolling background. Both work well - but because they implement separate Activities, how do I manage to run both inside one project?? ie the animation of the horse on the top of the scrolling background?
Here is my code for the separate projects:
FrameAnimateActivity
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.view.Menu;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
public class FrameAnimatedActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_frame_animated);
ImageView gyroView = (ImageView) findViewById(R.id.gyro);
//set the animation drawable as background
gyroView.setBackgroundResource(R.drawable.gyro_animation);
//create an animation drawable using the background
AnimationDrawable gyroAnimation = (AnimationDrawable) gyroView.getBackground();
//start the animation
gyroAnimation.start();
ImageView img_animation = (ImageView) findViewById(R.id.gyro);
TranslateAnimation animation = new TranslateAnimation(0.0f, 400.0f,
0.0f, 0.0f); // new TranslateAnimation(xFrom,xTo, yFrom,yTo)
animation.setDuration(5000); // animation duration
animation.setRepeatCount(5); // animation repeat count
animation.setRepeatMode(2); // repeat animation (left to right, right to left )
//animation.setFillAfter(true);
img_animation.startAnimation(animation); // start animation
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.frame_animated, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
And the code for the scrolling background:
MainActivity
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new MovingBackGround(this));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
MovingBackground.java
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class MovingBackGround extends SurfaceView implements
SurfaceHolder.Callback {
private Bitmap backGround;
public MovingBackGround(Context context) {
super(context);
backGround = BitmapFactory.decodeResource(context.getResources(),
R.drawable.ab);
setWillNotDraw(false);
}
#Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
doDrawRunning(canvas);
invalidate();
}
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
}
#Override
public void surfaceCreated(SurfaceHolder holder) {
}
#Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
/**
* Draws current state of the game Canvas.
*/
private int mBGFarMoveX = 0;
private int mBGNearMoveX = 0;
private void doDrawRunning(Canvas canvas) {
// decrement the far background
mBGFarMoveX = mBGFarMoveX - 1;
// decrement the near background
mBGNearMoveX = mBGNearMoveX - 4;
// calculate the wrap factor for matching image draw
int newFarX = backGround.getWidth() - (-mBGFarMoveX);
// if we have scrolled all the way, reset to start
if (newFarX <= 0) {
mBGFarMoveX = 0;
// only need one draw
canvas.drawBitmap(backGround, mBGFarMoveX, 0, null);
} else {
// need to draw original and wrap
canvas.drawBitmap(backGround, mBGFarMoveX, 0, null);
canvas.drawBitmap(backGround, newFarX, 0, null);
}
}
}
All the class is posted serially. This program was correct till the background of "GameActivity" was set by creating a custom view. But after then when i want to add single robot with every single touch in android device, it shows "an unexpected error".
WelcomeActivity
package com.emdad.androidapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
public class WelcomeActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_welcome);
final Button startButton=(Button) findViewById(R.id.androidButton);
startButton.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View arg0, MotionEvent arg1) {
switch (arg1.getAction()) {
case MotionEvent.ACTION_DOWN:
startButton.getBackground().setAlpha(100);
break;
case MotionEvent.ACTION_UP:
Intent intent=new Intent(WelcomeActivity.this, GameActivity.class);
startActivity(intent);
startButton.getBackground().setAlpha(255);
break;
case MotionEvent.ACTION_MOVE:
break;
default:
break;
}
return false;
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.welcome, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
GameActivity
package com.emdad.androidapp;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
public class GameActivity extends Activity {
GameView gameView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
gameView=new GameView(this);
setContentView(gameView);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.game, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
GameView
package com.emdad.androidapp;
import java.util.Random;
import android.content.Context;
import android.graphics.Point;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
public class GameView extends SurfaceView implements Callback{
Context context;
SurfaceHolder surfaceHolder;
DrawingThread drawingThread;
public GameView(Context context) {
super(context);
this.context=context;
surfaceHolder=getHolder();
surfaceHolder.addCallback(this);
drawingThread=new DrawingThread(this, context);
}
#Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
}
#Override
public void surfaceCreated(SurfaceHolder arg0) {
try {
drawingThread.start();
} catch (Exception e) {
restartThread();
}
}
private void restartThread() {
drawingThread.stopThread();
drawingThread=null;
drawingThread=new DrawingThread(this, context);
drawingThread.start();
}
#Override
public void surfaceDestroyed(SurfaceHolder arg0) {
drawingThread.stopThread();
}
#Override
public boolean onTouchEvent(MotionEvent event) {
Point touchPoint=new Point();
touchPoint=new Point((int)event.getX(), (int)event.getY());
Random random=new Random();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
drawingThread.allRobots.add(new Robot(drawingThread.allPossibleRobots.get(random.nextInt(6)), touchPoint));
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_MOVE:
drawingThread.allRobots.get(drawingThread.allRobots.size()-1).setCenter(touchPoint);
break;
default:
break;
}
return super.onTouchEvent(event);
}
}
DrawingThread
package com.emdad.androidapp;
import java.util.ArrayList;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.view.Display;
import android.view.WindowManager;
public class DrawingThread extends Thread{
private Canvas canvas;
private GameView gameView;
private Context context;
boolean threadFlag=false;
Bitmap backgroundBitmap;
int displayX, displayY;
ArrayList<Robot> allRobots;
ArrayList<Bitmap> allPossibleRobots;
public DrawingThread(GameView gameView, Context context) {
super();
this.gameView = gameView;
this.context = context;
initializaeAll();
}
private void initializaeAll() {
WindowManager windowManager=(WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display defaultDisplay=windowManager.getDefaultDisplay();
Point displayDimension=new Point();
defaultDisplay.getSize(displayDimension);
displayX=displayDimension.x;
displayY=displayDimension.y;
backgroundBitmap=BitmapFactory.decodeResource(context.getResources(), R.drawable.background1);
backgroundBitmap=Bitmap.createScaledBitmap(backgroundBitmap, displayX, displayY, true);
initializeAllPossibleRobots();
}
private void initializeAllPossibleRobots() {
allRobots=new ArrayList<Robot>();
allPossibleRobots=new ArrayList<Bitmap>();
allPossibleRobots.add(giveResizedRobotBitmap(R.drawable.android));
allPossibleRobots.add(giveResizedRobotBitmap(R.drawable.android2));
allPossibleRobots.add(giveResizedRobotBitmap(R.drawable.android3));
allPossibleRobots.add(giveResizedRobotBitmap(R.drawable.android6));
allPossibleRobots.add(giveResizedRobotBitmap(R.drawable.apple));
allPossibleRobots.add(giveResizedRobotBitmap(R.drawable.apple2));
}
private Bitmap giveResizedRobotBitmap(int resourceID) {
Bitmap tempBitmap=BitmapFactory.decodeResource(context.getResources(), resourceID);
tempBitmap=Bitmap.createScaledBitmap(tempBitmap, displayX/5, (tempBitmap.getHeight()/tempBitmap.getWidth())*(displayX/5), true);
return tempBitmap;
}
#Override
public void run() {
threadFlag=true;
while (threadFlag) {
canvas=gameView.surfaceHolder.lockCanvas();
try {
synchronized (canvas) {
updateDisplay();
}
} catch (Exception e) {
e.printStackTrace();
} finally{
if (canvas!=null) {
gameView.surfaceHolder.unlockCanvasAndPost(canvas);
}
}
try {
Thread.sleep(17);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
private void updateDisplay() {
canvas.drawBitmap(backgroundBitmap, 0, 0, null);
for (int i = 0; i < allRobots.size(); i++) {
Robot temprRobot=allRobots.get(i);
canvas.drawBitmap(temprRobot.robotBitmap, temprRobot.centerX-(temprRobot.width/2), temprRobot.centerY-(temprRobot.height/2), temprRobot.robotPaint);
}
}
public void stopThread() {
threadFlag=false;
}
}
Robot
package com.emdad.androidapp;
import android.graphics.Bitmap;
import android.graphics.Paint;
import android.graphics.Point;
public class Robot {
int centerX, centerY;
int height, width;
Bitmap robotBitmap;
Paint robotPaint;
public Robot(Bitmap bitmap) {
robotBitmap=bitmap;
centerX=centerY=0;
height=robotBitmap.getHeight();
width=robotBitmap.getWidth();
robotPaint=new Paint();
}
public Robot(Bitmap bitmap, int cX, int cY) {
this(bitmap);
centerX=cX;
centerY=cY;
}
public Robot(Bitmap bitmap, Point center) {
this(bitmap, center.x, center.y);
}
public void setCenter(Point centerPoint) {
centerX=centerPoint.x;
centerY=centerPoint.y;
}
}
thank you so much for reading. I have a textView that you can pinch zoom, and when I add "textview.setMovementMethod(new ScrollingMovementMethod());" to my code I can also scroll the zoomed textview which is exactly what I need. The problem is as soon as the text is zoomed, only the scrolling works but the pinch zoom doesnt work anymore, (unless I place one of my fingers outside the textview and the other inside). Any help will be really appreciated. I got the code from here: Pinch Zooming TextView
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.ScaleGestureDetector.SimpleOnScaleGestureListener;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView scaleGesture;
ScaleGestureDetector scaleGestureDetector;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scaleGesture = (TextView)findViewById(R.id.article);
scaleGesture.setText("this is some text");
scaleGestureDetector = new ScaleGestureDetector(this, new simpleOnScaleGestureListener());
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
#Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
scaleGestureDetector.onTouchEvent(event);
return true;
}
public class simpleOnScaleGestureListener extends
SimpleOnScaleGestureListener {
#Override
public boolean onScale(ScaleGestureDetector detector) {
// TODO Auto-generated method stub
float size = scaleGesture.getTextSize();
Log.d("TextSizeStart", String.valueOf(size));
float factor = detector.getScaleFactor();
Log.d("Factor", String.valueOf(factor));
float product = size*factor;
Log.d("TextSize", String.valueOf(product));
scaleGesture.setTextSize(TypedValue.COMPLEX_UNIT_PX, product);
size = scaleGesture.getTextSize();
Log.d("TextSizeEnd", String.valueOf(size));
return true;
}
}
}`
I just resolve this problem (with the same example) only add one "if" in my code:
#Override
public boolean onTouchEvent(MotionEvent event) {
// get how many fingers is in touch (in that case, if are more
// than 1, the user don't want do the scroll
if (event.getPointerCount() > 1) {
scaleGestureDetector.onTouchEvent(event);
return true;
}
return false;
}