Search in sources :

Example 56 with GestureDetector

use of android.view.GestureDetector in project android_frameworks_base by DirtyUnicorns.

the class Gallery method onAttachedToWindow.

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    if (mGestureDetector == null) {
        mGestureDetector = new GestureDetector(getContext(), this);
        mGestureDetector.setIsLongpressEnabled(true);
    }
}
Also used : GestureDetector(android.view.GestureDetector)

Example 57 with GestureDetector

use of android.view.GestureDetector in project chefly_android by chef-ly.

the class GetCookingActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_get_cooking);
    speechListener = new ttsUtteranceListener();
    DisplayMetrics metrics = getResources().getDisplayMetrics();
    width = metrics.widthPixels;
    height = metrics.heightPixels;
    //View Pager
    pager = (ViewPager) findViewById(R.id.viewpager);
    // Gesture Detector to repeat the current step when it detects a single tap on the screen
    final GestureDetector gestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (hasDirections) {
                if (step < directions.size()) {
                    read(directions.get(step));
                } else {
                    read(getResources().getString(R.string.bonAppetit));
                }
            }
            return super.onSingleTapConfirmed(e);
        }

        @Override
        public void onLongPress(MotionEvent e) {
            super.onLongPress(e);
        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            return super.onDoubleTap(e);
        }
    });
    // set on touch listener to ViewPager
    pager.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return gestureDetector.onTouchEvent(event);
        }
    });
    pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            step = position;
            updateStepText();
            read(directions.get(position));
        }

        @Override
        public void onPageSelected(int position) {
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    // Text view to display the current step number
    stepText = (TextView) findViewById(R.id.step);
    //Exit Button
    Button exit;
    exit = (Button) findViewById(R.id.exit);
    exit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            setResult(RESULT_OK);
            finish();
        }
    });
    ImageButton btnSpeak;
    btnSpeak = (ImageButton) findViewById(R.id.btnSpeak);
    btnSpeak.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
        }
    });
    textToSpeech = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {

        @Override
        public void onInit(int status) {
            if (status != TextToSpeech.ERROR) {
                textToSpeech.setLanguage(Locale.US);
                // Log.d(TAG, "Quality -> " + textToSpeech.getVoice().getQuality());
                if (directions.size() > 0) {
                    read(directions.get(0));
                }
            }
        }
    });
    // TODO replace with speech recognizer
    Button ingredBtn = (Button) findViewById(R.id.ingredientsBtn);
    ingredBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            FragmentManager fm = getSupportFragmentManager();
            ingredientsPopup.show(fm, "Ingredients");
            getSupportFragmentManager().executePendingTransactions();
            if (ingredientsPopup.getDialog().getWindow() != null)
                ingredientsPopup.getDialog().getWindow().setLayout((6 * width) / 7, (4 * height) / 5);
        }
    });
    // TODO replace with speech recognizer
    Button direcBtn = (Button) findViewById(R.id.directionsBtn);
    direcBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            FragmentManager fm = getSupportFragmentManager();
            if (directionsPopup != null) {
                directionsPopup.show(fm, "Directions");
                getSupportFragmentManager().executePendingTransactions();
                if (directionsPopup.getDialog().getWindow() != null)
                    directionsPopup.getDialog().getWindow().setLayout((6 * width) / 7, (4 * height) / 5);
            } else {
                Log.d(TAG, "Directions pop up is null.  Directions size = " + directions.size());
            }
        }
    });
    int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO);
    if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.RECORD_AUDIO }, PERMISSIONS_REQUEST_RECORD_AUDIO);
    //return;
    } else {
        voiceRec.runRec();
    }
}
Also used : GestureDetector(android.view.GestureDetector) TextToSpeech(android.speech.tts.TextToSpeech) DisplayMetrics(android.util.DisplayMetrics) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ViewPager(android.support.v4.view.ViewPager) MotionEvent(android.view.MotionEvent) FragmentManager(android.support.v4.app.FragmentManager) ImageButton(android.widget.ImageButton) ImageButton(android.widget.ImageButton) Button(android.widget.Button)

Example 58 with GestureDetector

use of android.view.GestureDetector in project JustAndroid by chinaltz.

the class AbWheelView method initData.

/**
	 * Initializes class data.
	 *
	 * @param context the context
	 */
private void initData(Context context) {
    mContext = context;
    gestureDetector = new GestureDetector(context, gestureListener);
    gestureDetector.setIsLongpressEnabled(false);
    scroller = new Scroller(context);
}
Also used : GestureDetector(android.view.GestureDetector) Scroller(android.widget.Scroller)

Example 59 with GestureDetector

use of android.view.GestureDetector in project Android-Developers-Samples by johnjohndoe.

the class BasicGestureDetectFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    View gestureView = getActivity().findViewById(R.id.sample_output);
    gestureView.setClickable(true);
    gestureView.setFocusable(true);
    // BEGIN_INCLUDE(init_detector)
    // First create the GestureListener that will include all our callbacks.
    // Then create the GestureDetector, which takes that listener as an argument.
    GestureDetector.SimpleOnGestureListener gestureListener = new GestureListener();
    final GestureDetector gd = new GestureDetector(getActivity(), gestureListener);
    /* For the view where gestures will occur, create an onTouchListener that sends
         * all motion events to the gesture detector.  When the gesture detector
         * actually detects an event, it will use the callbacks you created in the
         * SimpleOnGestureListener to alert your application.
        */
    gestureView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            gd.onTouchEvent(motionEvent);
            return false;
        }
    });
// END_INCLUDE(init_detector)
}
Also used : GestureDetector(android.view.GestureDetector) View(android.view.View) MotionEvent(android.view.MotionEvent)

Example 60 with GestureDetector

use of android.view.GestureDetector in project coursera-android by aporter.

the class ViewFlipperTestActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mCurrentLayoutState = 0;
    mFlipper = (ViewFlipper) findViewById(R.id.view_flipper);
    mTextView1 = (TextView) findViewById(R.id.textView1);
    mTextView2 = (TextView) findViewById(R.id.textView2);
    mTextView1.setText(String.valueOf(mCount));
    mGestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            if (velocityX < -10.0f) {
                mCurrentLayoutState = mCurrentLayoutState == 0 ? 1 : 0;
                switchLayoutStateTo(mCurrentLayoutState);
            }
            return true;
        }
    });
}
Also used : GestureDetector(android.view.GestureDetector) MotionEvent(android.view.MotionEvent)

Aggregations

GestureDetector (android.view.GestureDetector)133 MotionEvent (android.view.MotionEvent)46 ScaleGestureDetector (android.view.ScaleGestureDetector)23 Paint (android.graphics.Paint)22 View (android.view.View)22 Scroller (android.widget.Scroller)13 WindowManager (android.view.WindowManager)11 Handler (android.os.Handler)9 TextView (android.widget.TextView)9 SimpleOnGestureListener (android.view.GestureDetector.SimpleOnGestureListener)8 LayoutInflater (android.view.LayoutInflater)8 TypedArray (android.content.res.TypedArray)7 ImageView (android.widget.ImageView)7 ViewConfiguration (android.view.ViewConfiguration)6 OverScroller (android.widget.OverScroller)6 Matrix (android.graphics.Matrix)5 SystemServicesProxy (com.android.systemui.recents.misc.SystemServicesProxy)5 FlingAnimationUtils (com.android.systemui.statusbar.FlingAnimationUtils)5 SuppressLint (android.annotation.SuppressLint)4 Resources (android.content.res.Resources)4