List of usage examples for android.support.v4.view GestureDetectorCompat GestureDetectorCompat
public GestureDetectorCompat(Context context, OnGestureListener onGestureListener)
From source file:com.example.android.xyztouristattractions.ui.ShopsActivity.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 ShopsGridPagerAdapter(this, mShops); mAdapter.setOnChromeFadeListener(this); mGridViewPager.setAdapter(mAdapter); mDotsPageIndicator.setPager(mGridViewPager); mDotsPageIndicator.setOnPageChangeListener(mAdapter); topFrameLayout.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() { @Override//w w w. j a v a 2 s .com 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 shopsUri = getIntent().getParcelableExtra(Constants.EXTRA_SHOPS_URI); if (shopsUri != null) { new FetchDataAsyncTask(this).execute(shopsUri); UtilityService.clearNotification(this); UtilityService.clearRemoteNotifications(this); } else { finish(); } }
From source file:com.asburymotors.android.disneysocal.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); mDotsPageIndicator.setPager(mGridViewPager); mDotsPageIndicator.setOnPageChangeListener(mAdapter); topFrameLayout.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() { @Override/* ww w . jav a2 s.co 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(); } }
From source file:org.thoughtcrime.securesms.scribbles.widget.MotionView.java
private void init(@NonNull Context context, @Nullable AttributeSet attrs) { // I fucking love Android setWillNotDraw(false);// w w w. j a v a2 s . c o m selectedLayerPaint = new Paint(); selectedLayerPaint.setAlpha((int) (255 * Constants.SELECTED_LAYER_ALPHA)); selectedLayerPaint.setAntiAlias(true); this.editText = new EditText(context, attrs); ViewCompat.setAlpha(this.editText, 0); this.editText.setLayoutParams(new LayoutParams(1, 1, Gravity.TOP | Gravity.LEFT)); this.editText.setClickable(false); this.editText.setBackgroundColor(Color.TRANSPARENT); this.editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 1); this.editText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); this.addView(editText); this.editText.clearFocus(); this.editText.addTextChangedListener(this); // init listeners this.scaleGestureDetector = new ScaleGestureDetector(context, new ScaleListener()); this.rotateGestureDetector = new RotateGestureDetector(context, new RotateListener()); this.moveGestureDetector = new MoveGestureDetector(context, new MoveListener()); this.gestureDetectorCompat = new GestureDetectorCompat(context, new TapsListener()); setOnTouchListener(onTouchListener); updateUI(); }
From source file:org.mitre.svmp.activities.AppRTCVideoActivity.java
@Override public void onCreate(Bundle savedInstanceState) { // Get info passed to Intent final Intent intent = getIntent(); pkgName = intent.getStringExtra("pkgName"); apkPath = intent.getStringExtra("apkPath"); mDetector = new GestureDetectorCompat(this, new CustomScrollGesture()); /*/*from w w w.j a va 2s . c o m*/ * getWindow().requestFeature(Window.FEATURE_ACTION_BAR); * getActionBar().hide(); */ super.onCreate(savedInstanceState); qualitySpinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub HashMap<String, String> map = new HashMap<>(); if (position == 0) { map.put("height", ""); map.put("width", ""); } else if (position == 1) { map.put("height", "640"); map.put("width", "360"); } else if (position == 2) { map.put("height", "1280"); map.put("width", "720"); } map.put("type", "resolution_change"); JSONObject jObj = new JSONObject(map); AppRTCHelper.makeWebRTCRequest(jObj); } @Override public void onNothingSelected(AdapterView<?> parent) { // TODO Auto-generated method stub } }); }
From source file:org.rm3l.ddwrt.mgmt.RouterManagementActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_router_management); //Default values are not set by default //Android bug workaround: http://code.google.com/p/android/issues/detail?id=6641 PreferenceManager.setDefaultValues(this, DDWRTCompanionConstants.DEFAULT_SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE, R.xml.router_management_settings, false); this.dao = getDao(this); mRecyclerView = (RecyclerView) findViewById(R.id.routersListView); // use this setting to improve performance if you know that changes // in content do not change the layout size of the RecyclerView // allows for optimizations if all items are of the same size: mRecyclerView.setHasFixedSize(true); // use a linear layout manager mLayoutManager = new LinearLayoutManager(this); mLayoutManager.scrollToPosition(0);//from w w w .j av a 2 s .c o m mRecyclerView.setLayoutManager(mLayoutManager); // specify an adapter (see also next example) mAdapter = new RouterListRecycleViewAdapter(this, this.dao.getAllRouters()); mRecyclerView.setAdapter(mAdapter); /* * onClickDetection is done in this Activity's onItemTouchListener * with the help of a GestureDetector; * Tip by Ian Lake on G+ in a comment to this post: * https://plus.google.com/+LucasRocha/posts/37U8GWtYxDE */ mRecyclerView.addOnItemTouchListener(this); gestureDetector = new GestureDetectorCompat(this, new RouterManagementViewOnGestureListener()); addNewButton = (ImageButton) findViewById(R.id.router_list_add); addNewButton.setOnClickListener(this); mFeedbackDialog = new SendFeedbackDialog(this).getFeedbackDialog(); //Changelog Popup mChangelogDialog = new ChangeLogParameterized(this); //FIXME Disabled for now, because the listener may not be bound to the right positive button // if (mChangelogDialog.isFirstRun()) { // final AlertDialog clLogDialog = mChangelogDialog.getLogDialog(); // clLogDialog.show(); // if (mAdapter.getItemCount() == 0) { // //Override click on Positive Button, so we can display the 'Add Router' Dialog when user closes the ChangeLog popup // clLogDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // //Call initial onclick listener // mChangelogDialog.handlePositiveButtonClick(); // RouterManagementActivity.this.initOpenAddRouterFormIfNecessary(); // } // }); // } // } else { // initOpenAddRouterFormIfNecessary(); // } initOpenAddRouterFormIfNecessary(); }
From source file:com.ushahidi.android.ui.fragment.ListDeploymentFragment.java
private void initRecyclerView() { mDeploymentRecyclerView.setOnTouchListener(mListViewTouchListener); mRecyclerViewAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { @Override//w w w . ja va2 s . c om public void onChanged() { super.onChanged(); setEmptyView(); } }); mDeploymentRecyclerView.addOnItemTouchListener(this); mGestureDetector = new GestureDetectorCompat(getActivity(), new RecyclerViewOnGestureListener()); mDeploymentRecyclerView.setInteractiveToast(mInteractiveToast); mDeploymentRecyclerView.setAdapter(mRecyclerViewAdapter); setEmptyView(); }
From source file:com.duy.pascal.ui.view.console.ConsoleView.java
private void init(Context context) { mContext = context;/*from ww w.ja v a2 s .c om*/ mGestureDetector = new GestureDetectorCompat(getContext(), this); mGestureDetector.setOnDoubleTapListener(this); mPascalPreferences = new PascalPreferences(context); mAntiAlias = mPascalPreferences.useAntiAlias(); mGraphScreen = new GraphScreen(context, this); mGraphScreen.setAntiAlias(mAntiAlias); mConsoleScreen = new ConsoleScreen(mPascalPreferences); mConsoleScreen.setBackgroundColor(Color.BLACK); mTextRenderer = new TextRenderer( getTextSize(TypedValue.COMPLEX_UNIT_SP, mPascalPreferences.getConsoleTextSize())); mTextRenderer.setTypeface(mPascalPreferences.getConsoleFont()); mTextRenderer.setTextColor(Color.WHITE); mTextRenderer.setAntiAlias(mAntiAlias); firstLine = 0; mScreenBufferData.firstIndex = 0; mScreenBufferData.textConsole = null; mCursor = new ConsoleCursor(0, 0, Color.DKGRAY); mCursor.setCoordinate(0, 0); mCursor.setCursorBlink(true); mCursor.setVisible(true); }
From source file:com.stfalcon.frescoimageviewer.ImageViewerView.java
private void init() { inflate(getContext(), R.layout.image_viewer, this); backgroundView = findViewById(R.id.backgroundView); pager = (MultiTouchViewPager) findViewById(R.id.pager); dismissContainer = (ViewGroup) findViewById(R.id.container); swipeDismissListener = new SwipeToDismissListener(findViewById(R.id.dismissView), this, this); dismissContainer.setOnTouchListener(swipeDismissListener); directionDetector = new SwipeDirectionDetector(getContext()) { @Override/*ww w. j a v a 2s . co m*/ public void onDirectionDetected(Direction direction) { ImageViewerView.this.direction = direction; } }; scaleDetector = new ScaleGestureDetector(getContext(), new ScaleGestureDetector.SimpleOnScaleGestureListener()); gestureDetector = new GestureDetectorCompat(getContext(), new GestureDetector.SimpleOnGestureListener() { @Override public boolean onSingleTapConfirmed(MotionEvent e) { if (pager.isScrolled()) { onClick(e, isOverlayWasClicked); } return false; } }); pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { adapter.stopVideoPlayback(); } @Override public void onPageSelected(int position) { } @Override public void onPageScrollStateChanged(int state) { scrollState = state; if (state == ViewPager.SCROLL_STATE_IDLE) { modifyData(); } } }); }
From source file:com.lwz.dragpanelayout.view.DragPaneLayout.java
public DragPaneLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mDensity = context.getResources().getDisplayMetrics().density; mViewDragCallback = new ViewDragCallback(); mDragHelper = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, mViewDragCallback); mDragHelper.setMinVelocity(MIN_FLING_VELOCITY * mDensity); ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO); // So that we can catch the back button ? setFocusableInTouchMode(true);// ww w.ja va 2 s . c o m setClickable(true); ViewGroupCompat.setMotionEventSplittingEnabled(this, false); mGestureDetector = new GestureDetectorCompat(context, mGestureListener); }
From source file:uk.co.threeonefour.android.snowball.activities.game.GameActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_game); imageView = (GraphicsView) findViewById(R.id.view_game_image); textInputView = (TextInputView) findViewById(R.id.view_game_text_input); textView = (TextView) findViewById(R.id.view_game_text_output); textScrollView = (ScrollView) findViewById(R.id.view_game_text_output_scroll); progressBar = (ProgressBar) findViewById(R.id.view_game_progressbar); imageView.setVisibility(View.INVISIBLE); textInputView.setVisibility(View.INVISIBLE); textView.setVisibility(View.INVISIBLE); textScrollView.setVisibility(View.INVISIBLE); progressBar.setVisibility(View.VISIBLE); textInputView.setTextInputHandler(this); textView.setMovementMethod(LinkMovementMethod.getInstance()); formatter = new OutputFormatter(); formatter.setWordClickedHandler(this); formatter.setTextColor(textView.getCurrentTextColor()); formatter.setHighlightDirections(true); formatter.setClickableText(true);/*from w w w . java2 s.c o m*/ gestureDetector = new GestureDetectorCompat(this, new MyGestureListener()); graphicsHandler = new QueuedGraphicsHandler(); graphicsHandlerContext = new GraphicsContext(); level9 = new IcyVm(graphicsHandler, new MyFilehandler(), new PersistableGameStateFactory()); createTask = new AsyncTask<Void, Integer, Boolean>() { @Override protected Boolean doInBackground(Void... arg0) { try { AssetManager assetManager = getAssets(); InputStream in = assetManager.open("games/SNOWBALL.SNA"); ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtils.copy(in, out); level9.loadGame(out.toByteArray()); level9.startGame(); } catch (IOException e) { Log.e("game", "Failed to load file", e); } /* configure the selected game state */ Bundle extras = getIntent().getExtras(); if (extras != null) { gameStateSlot = extras.getInt(IntentConstants.GAME_STATE_SLOT, -1); } if (gameStateSlot == -1) { // TODO should never get here without a slot selected; use dao to get default slot id gameStateSlot = 0; } return true; } @Override protected void onPostExecute(Boolean result) { imageView.setVisibility(View.VISIBLE); textInputView.setVisibility(View.VISIBLE); textView.setVisibility(View.VISIBLE); textScrollView.setVisibility(View.VISIBLE); progressBar.setVisibility(View.GONE); GameState gameState = gameStateDao.loadGameState(gameStateSlot); GameStateSummary gameStateSummary = gameStateDao.loadGameStateSummary(gameStateSlot); if (gameState != null && gameStateSummary != null) { level9.setGameState(gameState); graphicsHandlerContext.setBitmap(gameStateDao.loadGraphics(gameStateSummary.getSlot())); imageView.setBitmap(graphicsHandlerContext.getBitmap()); textView.setText(""); processOutputText(gameStateSummary.getLastLocation()); // TODO hacky adding in a sneaky look because VM is not in the correct state for some reason level9.execute("look"); // TODO had to add this after putting into background task imageView.invalidate(); } else { String text = level9.getText().trim(); processOutput(text); } /* did we get a restore whilst we were initialising? */ if (restoredGameState != null) { level9.setGameState(restoredGameState); ramSaveSlots = restoredRamSaveSlots; imageView.setBitmap(restoredBitmap); gameStateSlot = restoredGameStateSlot; restoredGameState = null; restoredRamSaveSlots = null; restoredBitmap = null; restoredGameStateSlot = 0; } initialised = true; } }; createTask.execute((Void) null); }