Doubletap-to-Zoom in Android - java

I have a question to a doubletap-to-zoom action.
With the GestureDetector I got a list of gestures like the doubletap function:
#Override
public boolean onDoubleTap(MotionEvent event)
{
//Scrollanimation
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
Log.d(DEBUG_TAG, "");
}
Log.d(DEBUG_TAG, "onDoubleTap: ");
return true;
}
Now I want to implement a scroll function that enables a scale function by scrolling. How can I implement a scale effect without a scale detector that has to be extended by my MainClass?

DoubleTap is for something like that:
finger down,
finger up,
finger down,
finger up //end of interaction and here event is send onDoubleTap
but ScaleGestureDetector.SimpleOnScaleGestureListener will provide you callbacks in two scenarios:
One:
two fingers down, onScaleBegin
moving two fingers (scaling) onScale
end of interaction onScaleEnd
Second:
one finger down
one finger up (quick)
one finger down
moving finger onScaleBegin and onScale
one finger up onScaleEnd
The second allows you to scale with one finger.

Related

How to make a "swipe up" function like in many custom launchers?

I'm doing my own custom launcher for Android at the moment. Everything works so far. But there is one point where I need help.
I would like to do something like a swipe up on the home screen to display all installed apps. Therefore I do not want to start a new activity, cause of the delay.
Maybe it's possible to change the layout file with something like an animation when a gesture is detected? And how would I detect the swipe?
It's really easy to detect motion:
someViewLikeLinearLayout.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
//put finger on screen
return true;
case MotionEvent.ACTION_UP:
//release the finger
return true;
}
}
});
Just switch event and you can get many actions via MotionEvent
Good luck!

Detecting hover/swipe over a button

I wish to create a simple game for Android, where the player will be shown a table of buttons. He should have the ability to swipe/drag his fingers over some buttons, and the result of his move should only be displayed after he stops touching the screen.
I can see when Action_UP and Action_Down is called, but I can't use Action_HOVER_MOVE:
View.OnTouchListener OTL = new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction()==MotionEvent.ACTION_DOWN
|| motionEvent.getAction()==MotionEvent.ACTION_HOVER_MOVE)
{
Button B = (Button)view;
if (B.isActivated())
{
String letter = B.getText()+"";
word+=letter;
}
B.setActivated(false);
Toast t = Toast.makeText(MainActivity.this,word,Toast.LENGTH_SHORT);
t.show();
}
if (motionEvent.getAction()==MotionEvent.ACTION_UP)
{
Toast t = Toast.makeText(MainActivity.this,word,Toast.LENGTH_SHORT);
t.show();
word="";
resetButtons();
}
return true;
}
};
How to detect swipe over other buttons?
Per the docs, you probably want ACTION_MOVE
int ACTION_MOVE
Constant for getActionMasked(): A change has happened during a press gesture (between ACTION_DOWN and ACTION_UP). The motion contains the most recent point, as well as any intermediate points since the last down or move event.
You're having trouble with ACTION_HOVER_MOVE because:
int ACTION_HOVER_MOVE
Constant for getActionMasked(): A change happened but the pointer is not down (unlike ACTION_MOVE). The motion contains the most recent point, as well as any intermediate points since the last hover move event.
This action is always delivered to the window or view under the pointer.
This action is not a touch event so it is delivered to onGenericMotionEvent(MotionEvent) rather than onTouchEvent(MotionEvent).
Source: https://developer.android.com/reference/android/view/MotionEvent.html#ACTION_MOVE

How to get the exact touch position of a image?

I have an idea for implementing of a login with password as the image touch positions when the member touch the same position I have to login the user.Can anyone help me how to implement it I can get the position of screen only. and the x and y coordinated are changing even when I touch the same position.
I would say create a custom View that extends ImageView:
public class PasswordView extends ImageView {
public PasswordView(Context context) {
super(context);
// Any additional PasswordView setup
}
#Override
public boolean onTouchEvent(MotionEvent event) {
float xTouchPos = event.getX();
float yTouchPos = event.getY();
// If the PasswordView was clicked
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// Check if they touched in the secret spot
}
return super.onTouchEvent(event);
}
}
By subclassing ImageView, you will still have access to all the standard features of an ImageView (setting an image source, etc.) and you will also be able to add the additional functionality for checking a user's touch position.
Here's an example project that uses onTouchEvent.

Android- Swiping Across Multiple Buttons

I've implemented a grid of buttons using a grid layout. I'm trying to allow for a single swipe to activate multiple buttons. When the user touches any one of the buttons, I call a function with the specific button pressed to take the according action. But, currently, I can only activate one button per touch. Multi-touch works, but not a single swipe. The problem is that while the onTouch function is called continuously the view object that I use to determine the button pressed is only updated on the initial touch. What I need to do is get the id's of all of the buttons that were swiped across.
Thanks.
#Override
public boolean onTouch(View v, MotionEvent event)
{
super.onTouchEvent(event);
if (event.getAction() == MotionEvent.ACTION_MOVE)
{
switch (v.getId())
{
case R.id.padZeroZero:
padTouch(0,0);
break;
case R.id.padZeroOne:
padTouch(0,1);
break;
case R.id.padZeroTwo:
padTouch(0,2);
break;
//There's a lot more cases (it's a 9x8 grid), but they all do the same thing.
}
}
return false;
}

2 Simultaneous Android Touches / not triggered

So hi there.
I have a simple Layout with 2 Views in it. Both have an onTouchListener attached.
view.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent event) {
System.out.println("Touching");
return false;
}
});
But when I open the application on my phone and touch the first view and do NOT relase my finger and touch the second view with another finger, the second view wont trigger the touch event. why is this so?
I think in this case both touches are passed to the first view as a multi-touch event. So this is one event but contains (I forgot the details) both touch positions.

Categories