List of usage examples for android.support.v4.view GestureDetectorCompat GestureDetectorCompat
public GestureDetectorCompat(Context context, OnGestureListener onGestureListener)
From source file:com.github.omadahealth.circularbarpager.library.CircularBarPager.java
/** * Init the view by getting the {@link CircularBar}, * the {@link android.support.v4.view.ViewPager} and the {@link com.viewpagerindicator.CirclePageIndicator}. * Init also some default values as PageTranformer etc... *//* w ww . j a v a2 s . com*/ private void initializeView(AttributeSet attrs, int defStyleAttr) { if (attrs != null) { final TypedArray attributes = mContext.getTheme().obtainStyledAttributes(attrs, R.styleable.CircularViewPager, defStyleAttr, 0); boolean enableOnClick = attributes .getBoolean(R.styleable.CircularViewPager_progress_pager_on_click_enabled, false); isPaddingSet = false; LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); RelativeLayout view = (RelativeLayout) inflater.inflate(R.layout.circularbar_view_pager, this); mCircularBar = (CircularBar) view.findViewById(R.id.circular_bar); mViewPager = (ViewPager) view.findViewById(R.id.view_pager); mCirclePageIndicator = (CirclePageIndicator) view.findViewById(R.id.circle_page_indicator); //Default init if (mCircularBar != null) { mCircularBar.loadStyledAttributes(attrs, defStyleAttr); } if (mViewPager != null) { mViewPager.setPageTransformer(false, new FadeViewPagerTransformer()); } //If we enable onClick, ie. we can switch between pages with both a swipe and a touch //Touch just goes to the next page % number of pages if (enableOnClick) { final GestureDetectorCompat tapGestureDetector = new GestureDetectorCompat(getContext(), new GestureDetector.SimpleOnGestureListener() { @Override public boolean onSingleTapConfirmed(MotionEvent e) { mViewPager.setCurrentItem( (mViewPager.getCurrentItem() + 1) % mViewPager.getAdapter().getCount()); return super.onSingleTapConfirmed(e); } }); if (mViewPager != null) { mViewPager.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { tapGestureDetector.onTouchEvent(event); return false; } }); } } } }
From source file:android.support.test.testapp.RecyclerViewFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final LayoutManagerType layoutManagerType = (LayoutManagerType) getArguments() .getSerializable(KEY_EXTRA_LAYOUT_MANAGER_TYPE); final View view = inflater.inflate(layoutManagerType.getLayoutId(), container, false); selectedItemView = (TextView) view.findViewById(layoutManagerType.getSelectedItemId()); recyclerView = (RecyclerView) view.findViewById(layoutManagerType.getRVId()); recyclerView/* w w w . j a v a 2s . c o m*/ .addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST)); recyclerView.setHasFixedSize(true); recyclerView.addOnItemTouchListener(this); gestureDetector = new GestureDetectorCompat(getActivity(), new ItemTouchGestureDetector()); layoutManager = getLayoutManager(layoutManagerType); recyclerView.setLayoutManager(layoutManager); // Specify an adapter which displays items List<String> items = makeItems(); adapter = ItemListAdapter.newItemListAdapter(items, inflater); recyclerView.setAdapter(adapter); return view; }
From source file:com.cryart.sabbathschool.view.SSReadingView.java
public SSReadingView(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); if (!isInEditMode()) { gestureDetector = new GestureDetectorCompat(context, new SSReadingView.GestureListener()); ssReadViewBridge = new SSReadViewBridge(context); this.setWebViewClient(new SSWebViewClient()); this.getSettings().setJavaScriptEnabled(true); this.addJavascriptInterface(ssReadViewBridge, bridgeName); }//from www . j a v a 2 s. co m }
From source file:com.google.blockly.android.ui.PendingDrag.java
/** * Constructs a new PendingDrag that, if accepted by the DragHandler, begins with the * {@code actionDown} event.//from w ww . j a v a 2 s. c om * * @param controller The activity's {@link BlocklyController}. * @param touchedView The initial touched {@link BlockView} of the drag. * @param actionDown The first {@link MotionEvent#ACTION_DOWN} event. */ PendingDrag(@NonNull BlocklyController controller, @NonNull BlockView touchedView, @NonNull MotionEvent actionDown) { if (actionDown.getAction() != MotionEvent.ACTION_DOWN) { throw new IllegalArgumentException(); } mController = controller; mHelper = controller.getWorkspaceHelper(); mLatestEventTime = actionDown.getEventTime(); mTouchedView = touchedView; mPointerId = actionDown.getPointerId(actionDown.getActionIndex()); int pointerIdx = actionDown.findPointerIndex(mPointerId); mTouchDownBlockX = (int) actionDown.getX(pointerIdx); mTouchDownBlockY = (int) actionDown.getY(pointerIdx); touchedView.getTouchLocationOnScreen(actionDown, mTouchDownScreen); mHelper.screenToWorkspaceCoordinates(mTouchDownScreen, mTouchDownWorkspace); mGestureDetector = new GestureDetectorCompat(mController.getContext(), new GestureListener()); mGestureDetector.onTouchEvent(actionDown); }
From source file:com.example.spencerdepas.translationapp.activities.DMVSimulationActivity.java
public void setUpGestures() { Log.d(TAG, "setUpGestures :"); GestureListener mGestureListener = new GestureListener(); mGestureListener.delegate = DMVSimulationActivity.this; gDetect = new GestureDetectorCompat(this, mGestureListener); }
From source file:de.uni_weimar.mheinz.androidtouchscope.display.HandleView.java
private void init() { mGestureDetector = new GestureDetectorCompat(getContext(), new SimpleGestureListener()); mShapeDrawable.setShape(new PathShape(mHandlePath, mBounds.width(), mBounds.height())); mShapeDrawable.setBounds(0, 0, (int) mBounds.width(), (int) mBounds.height()); setLayerType(LAYER_TYPE_SOFTWARE, mShapeDrawable.getPaint()); makeHandle();//from www.ja v a 2 s .c o m mIsOn = true; mMainTextPaint.setColor(Color.BLACK); mMainTextPaint.setTextSize(15); mMainTextPaint.setTextAlign(Paint.Align.CENTER); }
From source file:org.protocoder.fragments.EditorFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { v = inflater.inflate(R.layout.fragment_editor, container, false); edit = (EditText) v.findViewById(R.id.editText1); TextUtils.changeFont(getActivity(), edit, Fonts.CODE); currentSize = edit.getTextSize();//from w w w . j ava 2s. co m Button btnIncreaseSize = (Button) v.findViewById(R.id.increaseSize); btnIncreaseSize.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { currentSize += 1; edit.setTextSize(currentSize); } }); Button btnDecreaseSize = (Button) v.findViewById(R.id.decreaseSize); btnDecreaseSize.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { currentSize -= 1; edit.setTextSize(currentSize); } }); Bundle bundle = getArguments(); if (bundle != null) { String projectName = bundle.getString(Project.NAME); String projectFolder = bundle.getString(Project.FOLDER); MLog.d("mm", projectName); if (projectName != "") { loadProject(ProjectManager.getInstance().get(projectFolder, projectName)); } } edit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MLog.d(TAG, "" + getCurrentCursorLine(edit.getEditableText())); if (listener != null) { listener.onLineTouched(); } } }); // Set actionbar override setHasOptionsMenu(true); GestureDetectorCompat qq = new GestureDetectorCompat(getActivity(), new GestureDetector.OnGestureListener() { @Override public boolean onSingleTapUp(MotionEvent e) { MLog.d(TAG, "singleTapUp"); return false; } @Override public void onShowPress(MotionEvent e) { MLog.d(TAG, "showPress"); } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { MLog.d(TAG, "onScroll"); return false; } @Override public void onLongPress(MotionEvent e) { MLog.d(TAG, "onLongPress"); } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { MLog.d(TAG, "onFling"); return false; } @Override public boolean onDown(MotionEvent e) { MLog.d(TAG, "onDown"); return false; } }); return v; }
From source file:com.project.richard.insightjournal.ui.timerscreen.TimerFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment final View view = inflater.inflate(R.layout.fragment_timer, container, false); unbinder = ButterKnife.bind(this, view); final GestureDetectorCompat mGestureDetector = new GestureDetectorCompat(getContext(), new GestureListener()); mRecordToggleOn = getArguments().getBoolean(PRESET_RECORD_TOGGLE); mType = getArguments().getString(PRESET_TYPE); Cursor c = getActivity().getContentResolver().query(LogsProvider.Presets.PRESETS, null, PresetsColumns.TYPE + " = ?", new String[] { mType }, null); if (c != null && c.moveToFirst()) { mMaxDuration = c.getLong(c.getColumnIndex(PresetsColumns.DURATION)); mMaxPrep = c.getLong(c.getColumnIndex(PresetsColumns.PREPARATION_TIME)); c.close();/*from w ww. j av a 2 s . com*/ } else { Log.e(TAG, "Cannot find Preset"); } if (savedInstanceState != null) { mTimerRunning = savedInstanceState.getBoolean(BOOLEAN_TIMER_RUNNING); mDigitalTimerView.setText(TimerUtils.millisToDigital(savedInstanceState.getLong(LONG_TIMER_DURATION))); mCircleTimerView .setProgress((float) savedInstanceState.getLong(LONG_TIMER_DURATION) / mMaxDuration * 100); } else { mDigitalTimerView.setText(TimerUtils.millisToDigital(mMaxDuration)); } if (mRecordToggleOn && mType.equals(PresetsColumns.SITTING_MEDITAION)) { mTimerParentLayout.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { mGestureDetector.onTouchEvent(event); return true; } }); } mGoogleApiClient = new GoogleApiClient.Builder(getContext()) .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Override public void onConnected(@Nullable Bundle bundle) { Log.e(TAG, "connected"); if (!PermissionsUtils.checkLocationPermissions(getContext())) { Log.e(TAG, "permission needed"); PermissionsUtils.requestLocationPermissions(getActivity(), R.id.timer_screen_parent_layout); } mLastKnownLocation = FusedLocationApi.getLastLocation(mGoogleApiClient); if (mTimerService != null && mLastKnownLocation != null) { mTimerService.setmLastLocation(mLastKnownLocation); Intent intent = new Intent(getContext(), FetchAddressIntentService.class); intent.putExtra(FetchAddressIntentService.LATITUDE_EXTRA, mLastKnownLocation.getLatitude()); intent.putExtra(FetchAddressIntentService.LONTITUDE_EXTRA, mLastKnownLocation.getLongitude()); getContext().startService(intent); } else { Log.e(TAG, "location not fetched"); } } @Override public void onConnectionSuspended(int i) { Log.e(TAG, "connection suspended"); } }).addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() { @Override public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { Log.e(TAG, "connection failed"); } }).addApi(LocationServices.API).build(); return view; }
From source file:com.waz.zclient.pages.main.conversation.views.row.message.views.TextMessageWithTimestamp.java
public TextMessageWithTimestamp(final Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); LayoutInflater.from(context).inflate(R.layout.row_conversation_text_with_timestamp, this, true); setOrientation(VERTICAL);//from ww w. j av a 2 s . c om messageTextView = ViewUtils.getView(this, R.id.ltv__row_conversation__message); timestampTextView = ViewUtils.getView(this, R.id.ttv__row_conversation__timestamp); animationDuration = getResources().getInteger(R.integer.content__message_timestamp__animation_duration); textSizeRegular = context.getResources().getDimensionPixelSize(R.dimen.wire__text_size__regular); textSizeEmoji = context.getResources().getDimensionPixelSize(R.dimen.wire__text_size__emoji); messageTextView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return gestureDetector.onTouchEvent(event); } }); gestureDetector = new GestureDetectorCompat(context, this); }
From source file:com.example.android.xyztouristattractions.ui.AttractionsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final FrameLayout topFrameLayout = (FrameLayout) findViewById(R.id.topFrameLayout); mProgressBar = (ProgressBar) findViewById(R.id.progressBar); mGridViewPager = (GridViewPager) findViewById(R.id.gridViewPager); mDotsPageIndicator = (DotsPageIndicator) findViewById(R.id.dotsPageIndicator); mAdapter = new AttractionsGridPagerAdapter(this, mAttractions); mAdapter.setOnChromeFadeListener(this); mGridViewPager.setAdapter(mAdapter); topFrameLayout.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() { @Override//from w w w . ja va 2 s . c o m public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) { // Call through to super implementation insets = topFrameLayout.onApplyWindowInsets(insets); boolean round = insets.isRound(); // Store system window insets regardless of screen shape mInsets.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom()); if (round) { // On a round screen calculate the square inset to use. // Alternatively could use BoxInsetLayout, although calculating // the inset ourselves lets us position views outside the center // box. For example, slightly lower on the round screen (by giving // up some horizontal space). mInsets = Utils.calculateBottomInsetsOnRoundDevice(getWindowManager().getDefaultDisplay(), mInsets); // Boost the dots indicator up by the bottom inset FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mDotsPageIndicator .getLayoutParams(); params.bottomMargin = mInsets.bottom; mDotsPageIndicator.setLayoutParams(params); } mAdapter.setInsets(mInsets); return insets; } }); // Set up the DismissOverlayView mDismissOverlayView = (DismissOverlayView) findViewById(R.id.dismiss_overlay); mDismissOverlayView.setIntroText(getString(R.string.exit_intro_text)); mDismissOverlayView.showIntroIfNecessary(); mGestureDetector = new GestureDetectorCompat(this, new LongPressListener()); Uri attractionsUri = getIntent().getParcelableExtra(Constants.EXTRA_ATTRACTIONS_URI); if (attractionsUri != null) { new FetchDataAsyncTask(this).execute(attractionsUri); UtilityService.clearNotification(this); UtilityService.clearRemoteNotifications(this); } else { finish(); } }