Example usage for android.view GestureDetector GestureDetector

List of usage examples for android.view GestureDetector GestureDetector

Introduction

In this page you can find the example usage for android.view GestureDetector GestureDetector.

Prototype

public GestureDetector(Context context, OnGestureListener listener) 

Source Link

Document

Creates a GestureDetector with the supplied listener.

Usage

From source file:com.cuddlesoft.nori.ImageViewerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Get shared preferences.
    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    // Get data out of Intent sent by SearchActivity or restore them from the saved instance
    // state./* w w w. ja v a  2  s.c  o m*/
    int imageIndex;
    if (savedInstanceState != null && savedInstanceState.containsKey(BUNDLE_ID_IMAGE_INDEX)
            && savedInstanceState.containsKey(BUNDLE_ID_SEARCH_RESULT)) {
        imageIndex = savedInstanceState.getInt(BUNDLE_ID_IMAGE_INDEX);
        searchResult = savedInstanceState.getParcelable(BUNDLE_ID_SEARCH_RESULT);
        searchClient = ((SearchClient.Settings) savedInstanceState
                .getParcelable(BUNDLE_ID_SEARCH_CLIENT_SETTINGS)).createSearchClient();
    } else {
        final Intent intent = getIntent();
        imageIndex = intent.getIntExtra(SearchActivity.BUNDLE_ID_IMAGE_INDEX, 0);
        searchResult = intent.getParcelableExtra(SearchActivity.BUNDLE_ID_SEARCH_RESULT);
        searchClient = ((SearchClient.Settings) intent
                .getParcelableExtra(SearchActivity.BUNDLE_ID_SEARCH_CLIENT_SETTINGS)).createSearchClient();
    }

    // Request window features.
    supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    // Keep screen on, if enabled by the user.
    if (sharedPreferences.getBoolean(getString(R.string.preference_image_viewer_keepScreenOn_key), true)) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }

    // Populate content view.
    setContentView(R.layout.activity_image_viewer);

    // Set up the action bar.
    final ActionBar actionBar = getSupportActionBar();
    actionBar.hide();
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Create and set the image viewer Fragment pager adapter.
    imagePagerAdapter = new ImagePagerAdapter(getSupportFragmentManager());
    viewPager = (ImageViewerPager) findViewById(R.id.image_pager);
    viewPager.setAdapter(imagePagerAdapter);
    viewPager.setOnPageChangeListener(this);
    viewPager.setCurrentItem(imageIndex);

    // Set up the GestureDetector used to toggle the action bar.
    gestureDetector = new GestureDetector(this, gestureListener);
    viewPager.setOnMotionEventListener(this);

    // Set activity title.
    setTitle(searchResult.getImages()[imageIndex]);

    // Dim system UI.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        viewPager.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
    }
}

From source file:com.CloudRecognition.CloudReco.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.d(LOGTAG, "onCreate");
    super.onCreate(savedInstanceState);
    comm = new ConexionSiabra(this);
    vuforiaAppSession = new SampleApplicationSession(this);

    startLoadingAnimation();//  w  w  w .  j  a  va 2 s .  co  m

    vuforiaAppSession.initAR(this, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    // Creates the GestureDetector listener for processing double tap
    mGestureDetector = new GestureDetector(this, new GestureListener());

    mIsDroidDevice = android.os.Build.MODEL.toLowerCase().startsWith("droid");

}

From source file:io.github.data4all.activity.CameraActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "onCreate is called");

    // setting ignore warnings
    ignore = false;/*from   w w w .j  a  v a  2 s  .  c  om*/
    // remove title and status bar
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);

    // It is important to call the super method after the window-features
    // are requested
    super.onCreate(savedInstanceState);

    shutterCallback = new ShutterCallback() {
        public void onShutter() {
            final Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
            vibrator.vibrate(VIBRATION_DURATION);
        }
    };
    mDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float x, float y) {
            if (x > MIN_SWIPE_VELOCITY) {
                CameraActivity.this.switchMode(currentMappingMode - 1);
                return true;
            } else if (x < -MIN_SWIPE_VELOCITY) {
                CameraActivity.this.switchMode(currentMappingMode + 1);
                return true;
            }
            return false;
        }
    });

    // The filter's action is BROADCAST_CAMERA
    IntentFilter mStatusIntentFilter = new IntentFilter(OrientationListener.BROADCAST_CAMERA);
    // Instantiates a new DownloadStateReceiver
    CalibrationReceiver mCalibrationReceiver = new CalibrationReceiver();
    // Registers the DownloadStateReceiver and its intent filters
    LocalBroadcastManager.getInstance(this).registerReceiver(mCalibrationReceiver, mStatusIntentFilter);

}

From source file:com.emmaguy.todayilearned.PanView.java

public PanView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Sets up interactions
    mGestureDetector = new GestureDetector(context, new ScrollFlingGestureListener());
    mScroller = new OverScroller(context);
    mEdgeEffectLeft = new EdgeEffect(context);
    mEdgeEffectTop = new EdgeEffect(context);
    mEdgeEffectRight = new EdgeEffect(context);
    mEdgeEffectBottom = new EdgeEffect(context);

    mDrawBlurredPaint = new Paint();
    mDrawBlurredPaint.setDither(true);/*from w  ww .  ja  va  2 s. c om*/
}

From source file:com.acbelter.directionalcarousel.CarouselViewPager.java

public CarouselViewPager(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);

    mConfig = CarouselConfig.getInstance();
    mConfig.pagerId = getId();//w  w  w . j a v a2s  . c om
    mResources = context.getResources();
    mPackageName = context.getPackageName();
    mPageContentWidthId = mResources.getIdentifier("page_content_width", "dimen", mPackageName);
    mPageContentHeightId = mResources.getIdentifier("page_content_height", "dimen", mPackageName);

    DisplayMetrics dm = mResources.getDisplayMetrics();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CarouselViewPager, defStyle, 0);
    try {
        if (a != null) {
            mConfig.orientation = a.getInt(R.styleable.CarouselViewPager_android_orientation,
                    CarouselConfig.HORIZONTAL);
            mConfig.infinite = a.getBoolean(R.styleable.CarouselViewPager_infinite, true);
            mConfig.scrollScalingMode = a.getInt(R.styleable.CarouselViewPager_scrollScalingMode,
                    CarouselConfig.SCROLL_MODE_BIG_CURRENT);

            float bigScale = a.getFloat(R.styleable.CarouselViewPager_bigScale,
                    CarouselConfig.DEFAULT_BIG_SCALE);
            if (bigScale > 1.0f || bigScale < 0.0f) {
                bigScale = CarouselConfig.DEFAULT_BIG_SCALE;
                Log.w(TAG, "Invalid bigScale attribute. Default value " + CarouselConfig.DEFAULT_BIG_SCALE
                        + " will be used.");
            }
            mConfig.bigScale = bigScale;

            float smallScale = a.getFloat(R.styleable.CarouselViewPager_smallScale,
                    CarouselConfig.DEFAULT_SMALL_SCALE);
            if (smallScale > 1.0f || smallScale < 0.0f) {
                smallScale = CarouselConfig.DEFAULT_SMALL_SCALE;
                Log.w(TAG, "Invalid smallScale attribute. Default value " + CarouselConfig.DEFAULT_SMALL_SCALE
                        + " will be used.");
            } else if (smallScale > bigScale) {
                smallScale = bigScale;
                Log.w(TAG, "Invalid smallScale attribute. Value " + bigScale + " will be used.");
            }
            mConfig.smallScale = smallScale;

            mMinPagesOffset = (int) a.getDimension(R.styleable.CarouselViewPager_minPagesOffset,
                    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, dm));
            mSidePagesVisiblePart = a.getFloat(R.styleable.CarouselViewPager_sidePagesVisiblePart,
                    DEFAULT_SIDE_PAGES_VISIBLE_PART);
            mWrapPadding = (int) a.getDimension(R.styleable.CarouselViewPager_wrapPadding,
                    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm));
        }
    } finally {
        if (a != null) {
            a.recycle();
        }
    }

    mGestureListener = new SimpleOnGestureListener() {
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (getCarouselAdapter() != null) {
                getCarouselAdapter().sendSingleTap(mTouchedView, mTouchedItem);
            }
            mTouchedView = null;
            mTouchedItem = null;
            return true;
        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (getCarouselAdapter() != null) {
                getCarouselAdapter().sendDoubleTap(mTouchedView, mTouchedItem);
            }
            mTouchedView = null;
            mTouchedItem = null;
            return true;
        }
    };

    mGestureDetector = new GestureDetector(context, mGestureListener);
}

From source file:com.example.zayankovsky.homework.ui.ImageDetailActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.image_detail);
    getWindow().getDecorView().setBackgroundResource(
            PreferenceManager.getDefaultSharedPreferences(this).getString("theme", "light").equals("dark")
                    ? R.color.darkColorTransparent
                    : R.color.lightColorTransparent);

    // Set up activity to go full screen
    getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN);

    // Locate the main ImageView and TextView
    mImageView = (ImageView) findViewById(R.id.imageView);
    final TextView mTextView = (TextView) findViewById(R.id.textView);

    mSectionNumber = getIntent().getIntExtra(SECTION_NUMBER, 0);
    registerForContextMenu(mImageView);//  ww w.j  ava2s .co m
    mImageView.setLongClickable(false);

    // Enable some additional newer visibility and ActionBar features
    // to create a more immersive photo viewing experience
    final ActionBar actionBar = getSupportActionBar();

    if (actionBar != null) {
        // Set home as up
        actionBar.setDisplayHomeAsUpEnabled(true);

        // Hide and show the ActionBar and TextView as the visibility changes
        mImageView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int vis) {
                if ((vis & View.SYSTEM_UI_FLAG_LOW_PROFILE) != 0) {
                    actionBar.hide();
                    if (mSectionNumber == 1) {
                        mTextView.animate().translationY(mTextView.getHeight())
                                .setListener(new AnimatorListenerAdapter() {
                                    @Override
                                    public void onAnimationEnd(Animator animation) {
                                        mTextView.setVisibility(View.GONE);
                                    }
                                });
                    }
                } else {
                    actionBar.show();
                    if (mSectionNumber == 1) {
                        mTextView.animate().translationY(0).setListener(new AnimatorListenerAdapter() {
                            @Override
                            public void onAnimationStart(Animator animation) {
                                mTextView.setVisibility(View.VISIBLE);
                            }
                        });
                    }
                }
            }
        });

        // Start low profile mode and hide ActionBar
        mImageView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
        actionBar.hide();
    }

    GestureListener.init(this, mImageView);
    ScaleGestureListener.init(mImageView);

    // Use the ImageWorker to load the image into the ImageView
    // (so a single cache can be used over all pages in the ViewPager)
    // based on the extra passed in to this activity
    int position = getIntent().getIntExtra(POSITION, 0);
    switch (mSectionNumber) {
    case 0:
        GalleryWorker.loadImage(position, mImageView);
        break;
    case 1:
        FotkiWorker.loadImage(position, mImageView);
        mTextView.setText(getResources().getString(R.string.detail_text, FotkiWorker.getAuthor(),
                new SimpleDateFormat("d MMMM yyyy", Locale.getDefault()).format(FotkiWorker.getPublished())));
        break;
    case 2:
        ResourcesWorker.loadImage(position, mImageView);
        break;
    }
    setTitle(ImageWorker.getTitle());

    // First we create the GestureListener that will include all our callbacks.
    // Then we create the GestureDetector, which takes that listener as an argument.
    GestureDetector.SimpleOnGestureListener gestureListener = new GestureListener();
    final GestureDetector gd = new GestureDetector(this, gestureListener);

    ScaleGestureDetector.SimpleOnScaleGestureListener scaleGestureListener = new ScaleGestureListener();
    final ScaleGestureDetector sgd = new ScaleGestureDetector(this, scaleGestureListener);

    /* For the view where gestures will occur, we create an onTouchListener that sends
     * all motion events to the gesture detectors.  When the gesture detectors
     * actually detects an event, it will use the callbacks we created in the
     * SimpleOnGestureListener and SimpleOnScaleGestureListener to alert our application.
    */

    findViewById(R.id.frameLayout).setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            gd.onTouchEvent(motionEvent);
            sgd.onTouchEvent(motionEvent);
            return true;
        }
    });
}

From source file:com.github.crvv.wubinput.wubi.dictionary.suggestions.SuggestionStripView.java

public SuggestionStripView(final Context context, final AttributeSet attrs, final int defStyle) {
    super(context, attrs, defStyle);

    final LayoutInflater inflater = LayoutInflater.from(context);
    inflater.inflate(R.layout.suggestions_strip, this);

    mSuggestionsStrip = (ViewGroup) findViewById(R.id.suggestions_strip);
    mStripVisibilityGroup = new StripVisibilityGroup(this, mSuggestionsStrip, null, null);

    for (int pos = 0; pos < SuggestedWords.MAX_SUGGESTIONS; pos++) {
        final TextView word = new TextView(context, null, R.attr.suggestionWordStyle);
        word.setOnClickListener(this);
        word.setOnLongClickListener(this);
        mWordViews.add(word);//from  w w  w. java  2s  .  c  o  m
        final View divider = inflater.inflate(R.layout.suggestion_divider, null);
        mDividerViews.add(divider);
        final TextView info = new TextView(context, null, R.attr.suggestionWordStyle);
        info.setTextColor(Color.WHITE);
        info.setTextSize(TypedValue.COMPLEX_UNIT_DIP, DEBUG_INFO_TEXT_SIZE_IN_DIP);
    }

    mLayoutHelper = new SuggestionStripLayoutHelper(context, attrs, defStyle, mWordViews, mDividerViews, null);

    mMoreSuggestionsContainer = inflater.inflate(R.layout.more_suggestions, null);
    mMoreSuggestionsView = (MoreSuggestionsView) mMoreSuggestionsContainer
            .findViewById(R.id.more_suggestions_view);
    mMoreSuggestionsBuilder = new MoreSuggestions.Builder(context, mMoreSuggestionsView);

    final Resources res = context.getResources();
    mMoreSuggestionsModalTolerance = res
            .getDimensionPixelOffset(R.dimen.config_more_suggestions_modal_tolerance);
    mMoreSuggestionsSlidingDetector = new GestureDetector(context, mMoreSuggestionsSlidingListener);

    final TypedArray keyboardAttr = context.obtainStyledAttributes(attrs, R.styleable.Keyboard, defStyle,
            R.style.SuggestionStripView);
    keyboardAttr.recycle();
}

From source file:monakhv.android.samlib.AuthorListFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String[] from = { SQLController.COL_NAME, SQLController.COL_mtime, SQLController.COL_isnew,
            SQLController.COL_TGNAMES, SQLController.COL_URL };
    int[] to = { R.id.authorName, R.id.updated, R.id.icon, R.id.tgnames, R.id.authorURL };

    adapter = new SimpleCursorAdapter(getActivity(), R.layout.rowlayout, null, from, to,
            CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);

    SettingsHelper settings = new SettingsHelper(getActivity().getApplicationContext());

    adapter.setViewBinder(new AuthorViewBinder());
    order = settings.getAuthorSortOrder();
    setListAdapter(adapter);//w  w w.j  a v  a2 s .  c  om
    getLoaderManager().initLoader(AUTHOR_LIST_LOADER, null, this);
    detector = new GestureDetector(getActivity(), new ListSwipeListener(this));
}

From source file:com.gcssloop.diycode.activity.MainActivity.java

private void initMenu(ViewHolder holder) {
    Toolbar toolbar = holder.get(R.id.toolbar);
    toolbar.setLogo(R.mipmap.logo_actionbar);
    toolbar.setTitle("");
    DrawerLayout drawer = holder.get(R.id.drawer_layout);
    setSupportActionBar(toolbar);// w  w w  .j a  v  a2 s . c  o m
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    // ? 666
    final GestureDetector detector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            quickToTop(); // 
            return super.onDoubleTap(e);
        }
    });

    toolbar.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            detector.onTouchEvent(event);
            return false;
        }
    });

    toolbar.setOnClickListener(this);

    holder.setOnClickListener(this, R.id.fab);

    loadMenuData();
}

From source file:br.com.brolam.cloudvision.ui.NoteVisionActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_note_vision);
    this.toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//ww w  . j a  v a 2s . c om

    // Show the Up button in the action bar.
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    mPreview = (CameraSourcePreview) findViewById(R.id.preview);
    mGraphicOverlay = (GraphicOverlay<OcrGraphic>) findViewById(R.id.graphicOverlay);
    this.fabFlashOnOff = (FloatingActionButton) this.findViewById(R.id.fabFlashOnOff);
    this.fabCameraPlayStop = (FloatingActionButton) this.findViewById(R.id.fabCameraPlayStop);
    this.fabAdd = (FloatingActionButton) this.findViewById(R.id.fabAdd);
    this.contentNoteVisionCamera = this.findViewById(R.id.contentNoteVisionCamera);
    this.contentNoteVisionKeyboard = this.findViewById(R.id.contentNoteVisionKeyboard);
    this.editTextTitle = (EditText) this.findViewById(R.id.editTextTitle);
    this.editTextContent = (EditText) this.findViewById(R.id.editTextContent);

    setSaveInstanceState(savedInstanceState);

    // Check for the camera permission before accessing the camera.  If the
    // permission is not granted yet, request permission.
    int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
    if (rc == PackageManager.PERMISSION_GRANTED) {
        createCameraSource();
    } else {
        ActivityHelper.requestCameraPermission(TAG, this, mGraphicOverlay);
    }

    gestureDetector = new GestureDetector(this, new CaptureGestureListener());
    scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener());

    /*
    * Criar um LoginHelper para registrar o login do usurio no aplicativo.
    * Veja os mtodos onResume, onPause e onActivityResult para mais detalhes
    * sobre o fluxo de registro do usurio.
    */
    this.loginHelper = new LoginHelper(this, null, this);

}