use of android.view.GestureDetector in project EngineDriver by JMRI.
the class gamepad_test method onCreate.
/**
* Called when the activity is first created.
*/
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mainapp = (threaded_application) getApplication();
if (mainapp.isForcingFinish()) {
// expedite
return;
}
result = RESULT_CANCELED;
Bundle extras = getIntent().getExtras();
if (extras != null) {
whichGamepadNo = extras.getString("whichGamepadNo");
}
mainapp.applyTheme(this);
setContentView(R.layout.gamepad_test);
// put pointer to this activity's handler in main app's shared variable
myGesture = new GestureDetector(this);
mainapp = (threaded_application) this.getApplication();
prefs = getSharedPreferences("jmri.enginedriver_preferences", 0);
prefGamepadTestEnforceTestingSimple = prefs.getBoolean("prefGamepadTestEnforceTestingSimple", getResources().getBoolean(R.bool.prefGamepadTestEnforceTestingSimpleDefaultValue));
// tone generator for feedback sounds
tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, preferences.getIntPrefValue(prefs, "prefGamePadFeedbackVolume", getApplicationContext().getResources().getString(R.string.prefGamePadFeedbackVolumeDefaultValue)));
// set listener for select loco buttons
bDpadUp = (Button) findViewById(R.id.gamepad_test_dpad_up);
bDpadUp.setClickable(false);
bDpadDown = (Button) findViewById(R.id.gamepad_test_dpad_down);
bDpadDown.setClickable(false);
bDpadLeft = (Button) findViewById(R.id.gamepad_test_dpad_left);
bDpadLeft.setClickable(false);
bDpadRight = (Button) findViewById(R.id.gamepad_test_dpad_right);
bDpadRight.setClickable(false);
bButtonX = (Button) findViewById(R.id.gamepad_test_button_x);
bButtonX.setClickable(false);
bButtonY = (Button) findViewById(R.id.gamepad_test_button_y);
bButtonY.setClickable(false);
bButtonA = (Button) findViewById(R.id.gamepad_test_button_a);
bButtonA.setClickable(false);
bButtonB = (Button) findViewById(R.id.gamepad_test_button_b);
bButtonB.setClickable(false);
bButtonStart = (Button) findViewById(R.id.gamepad_test_button_start);
bButtonStart.setClickable(false);
bButtonEnter = (Button) findViewById(R.id.gamepad_test_button_enter);
bButtonEnter.setClickable(false);
// tvGamepadMode =(TextView) findViewById(R.id.gamepad_test_mode);
tvGamepadAllKeyCodes = (TextView) findViewById(R.id.gamepad_test_all_keycodes);
tvGamepadKeyCode = (TextView) findViewById(R.id.gamepad_test_keycode);
tvGamepadKeyFunction = (TextView) findViewById(R.id.gamepad_test_keyfunction);
tvGamepadComplete = (TextView) findViewById(R.id.gamepad_test_complete);
tvGamepadKeyCode.setText("");
tvGamepadKeyFunction.setText("");
tvGamepadComplete.setText(R.string.gamepadTestIncomplete);
// Set the options for the mode.
Spinner mode_spinner = (Spinner) findViewById(R.id.gamepad_test_mode);
// ArrayAdapter<?> spinner_adapter = ArrayAdapter.createFromResource(this, R.array.prefGamePadTypeOptions, android.R.layout.simple_spinner_item);
ArrayAdapter<?> spinner_adapter = ArrayAdapter.createFromResource(this, R.array.prefGamePadTypeEntryValues, android.R.layout.simple_spinner_item);
spinner_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mode_spinner.setAdapter(spinner_adapter);
mode_spinner.setOnItemSelectedListener(new spinner_listener());
setGamepadKeys();
// Set the button
Button cancelButton = (Button) findViewById(R.id.gamepad_test_button_cancel);
gamepad_test.cancel_button_listener cancel_click_listener = new gamepad_test.cancel_button_listener();
cancelButton.setOnClickListener(cancel_click_listener);
Button resetButton = (Button) findViewById(R.id.gamepad_test_button_reset);
gamepad_test.reset_button_listener reset_click_listener = new gamepad_test.reset_button_listener();
resetButton.setOnClickListener(reset_click_listener);
Button skipButton = (Button) findViewById(R.id.gamepad_test_button_skip);
if (whichGamepadNo.equals(" ")) {
resetButton.setVisibility(View.GONE);
skipButton.setVisibility(View.GONE);
cancelButton.setText(R.string.gamepadTestCancelNonForced);
TextView tvHelpText = (TextView) findViewById(R.id.gamepad_test_help);
tvHelpText.setText(R.string.gamepadTestHelpNonForced);
} else {
gamepad_test.skip_button_listener skip_click_listener = new gamepad_test.skip_button_listener();
skipButton.setOnClickListener(skip_click_listener);
}
}
use of android.view.GestureDetector in project Applozic-Android-SDK by AppLozic.
the class TouchImageView method sharedConstructing.
private void sharedConstructing(Context context) {
super.setClickable(true);
this.context = context;
mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
mGestureDetector = new GestureDetector(context, new GestureListener());
matrix = new Matrix();
prevMatrix = new Matrix();
m = new float[9];
normalizedScale = 1;
if (mScaleType == null) {
mScaleType = ScaleType.FIT_CENTER;
}
minScale = 1;
maxScale = 3;
superMinScale = SUPER_MIN_MULTIPLIER * minScale;
superMaxScale = SUPER_MAX_MULTIPLIER * maxScale;
setImageMatrix(matrix);
setScaleType(ScaleType.MATRIX);
setState(State.NONE);
onDrawReady = false;
super.setOnTouchListener(new PrivateOnTouchListener());
}
use of android.view.GestureDetector in project weiui by kuaifan.
the class SubsamplingScaleImageView method setGestureDetector.
private void setGestureDetector(final Context context) {
this.detector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (panEnabled && readySent && vTranslate != null && e1 != null && e2 != null && (Math.abs(e1.getX() - e2.getX()) > 50 || Math.abs(e1.getY() - e2.getY()) > 50) && (Math.abs(velocityX) > 500 || Math.abs(velocityY) > 500) && !isZooming) {
PointF vTranslateEnd = new PointF(vTranslate.x + (velocityX * 0.25f), vTranslate.y + (velocityY * 0.25f));
float sCenterXEnd = ((getWidth() / 2) - vTranslateEnd.x) / scale;
float sCenterYEnd = ((getHeight() / 2) - vTranslateEnd.y) / scale;
new AnimationBuilder(new PointF(sCenterXEnd, sCenterYEnd)).withEasing(EASE_OUT_QUAD).withPanLimited(false).withOrigin(ORIGIN_FLING).start();
return true;
}
return super.onFling(e1, e2, velocityX, velocityY);
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
performClick();
return true;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
if (zoomEnabled && readySent && vTranslate != null) {
// Hacky solution for #15 - after a double tap the GestureDetector gets in a state
// where the next fling is ignored, so here we replace it with a new one.
setGestureDetector(context);
if (quickScaleEnabled) {
// Store quick scale params. This will become either a double tap zoom or a
// quick scale depending on whether the user swipes.
vCenterStart = new PointF(e.getX(), e.getY());
vTranslateStart = new PointF(vTranslate.x, vTranslate.y);
scaleStart = scale;
isQuickScaling = true;
isZooming = true;
quickScaleLastDistance = -1F;
quickScaleSCenter = viewToSourceCoord(vCenterStart);
quickScaleVStart = new PointF(e.getX(), e.getY());
quickScaleVLastPoint = new PointF(quickScaleSCenter.x, quickScaleSCenter.y);
quickScaleMoved = false;
// We need to get events in onTouchEvent after this.
return false;
} else {
// Start double tap zoom animation.
doubleTapZoom(viewToSourceCoord(new PointF(e.getX(), e.getY())), new PointF(e.getX(), e.getY()));
return true;
}
}
return super.onDoubleTapEvent(e);
}
});
}
use of android.view.GestureDetector in project weiui by kuaifan.
the class GestureCropImageView method setupGestureListeners.
private void setupGestureListeners() {
mGestureDetector = new GestureDetector(getContext(), new GestureListener(), null, true);
mScaleDetector = new ScaleGestureDetector(getContext(), new ScaleListener());
mRotateDetector = new RotationGestureDetector(new RotateListener());
}
use of android.view.GestureDetector in project Rocket by mozilla-tw.
the class SubsamplingScaleImageView method setGestureDetector.
private void setGestureDetector(final Context context) {
this.detector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (panEnabled && readySent && vTranslate != null && e1 != null && e2 != null && (Math.abs(e1.getX() - e2.getX()) > 50 || Math.abs(e1.getY() - e2.getY()) > 50) && (Math.abs(velocityX) > 500 || Math.abs(velocityY) > 500) && !isZooming) {
PointF vTranslateEnd = new PointF(vTranslate.x + (velocityX * 0.25f), vTranslate.y + (velocityY * 0.25f));
float sCenterXEnd = ((getWidth() / 2) - vTranslateEnd.x) / scale;
float sCenterYEnd = ((getHeight() / 2) - vTranslateEnd.y) / scale;
new AnimationBuilder(new PointF(sCenterXEnd, sCenterYEnd)).withEasing(EASE_OUT_QUAD).withPanLimited(false).withOrigin(ORIGIN_FLING).start();
return true;
}
return super.onFling(e1, e2, velocityX, velocityY);
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
performClick();
return true;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
if (zoomEnabled && readySent && vTranslate != null) {
// Hacky solution for #15 - after a double tap the GestureDetector gets in a state
// where the next fling is ignored, so here we replace it with a new one.
setGestureDetector(context);
if (quickScaleEnabled) {
// Store quick scale params. This will become either a double tap zoom or a
// quick scale depending on whether the user swipes.
vCenterStart = new PointF(e.getX(), e.getY());
vTranslateStart = new PointF(vTranslate.x, vTranslate.y);
scaleStart = scale;
isQuickScaling = true;
isZooming = true;
quickScaleLastDistance = -1F;
quickScaleSCenter = viewToSourceCoord(vCenterStart);
quickScaleVStart = new PointF(e.getX(), e.getY());
quickScaleVLastPoint = new PointF(quickScaleSCenter.x, quickScaleSCenter.y);
quickScaleMoved = false;
// We need to get events in onTouchEvent after this.
return false;
} else {
// Start double tap zoom animation.
doubleTapZoom(viewToSourceCoord(new PointF(e.getX(), e.getY())), new PointF(e.getX(), e.getY()));
return true;
}
}
return super.onDoubleTapEvent(e);
}
});
}
Aggregations