List of usage examples for android.view GestureDetector.SimpleOnGestureListener GestureDetector.SimpleOnGestureListener
GestureDetector.SimpleOnGestureListener
From source file:com.acbelter.scheduleview.ScheduleView.java
private void init(Context context) { if (!isInEditMode()) { mOverScroller = new OverScroller(context); mGestureListener = new GestureDetector.SimpleOnGestureListener() { @Override/*ww w. ja v a 2 s .c o m*/ public boolean onDown(MotionEvent e) { if (DEBUG) { Log.d(TAG, "onDown() y=" + mListY); } releaseEdgeEffects(); mOverScroller.forceFinished(true); return true; } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (DEBUG) { Log.d(TAG, "onFling() y=" + mListY); } // Fling isn't needed if (mDeltaHeight < 0) { return true; } mScrollDirection = velocityY > 0 ? 1 : -1; mOverScroller.fling(0, mListY, 0, (int) velocityY, 0, 0, -mDeltaHeight, 0); if (!awakenScrollBars()) { ViewCompat.postInvalidateOnAnimation(ScheduleView.this); } return true; } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { for (int i = 0; i < getChildCount(); i++) { getChildAt(i).setPressed(false); } mListY -= (int) distanceY; recalculateOffset(); positionItemViews(); if (mListY == 0) { mTopEdgeEffect.onPull(distanceY / (float) getHeight()); mTopEdgeEffectActive = true; } if (mListY == -mDeltaHeight) { mBottomEdgeEffect.onPull(distanceY / (float) getHeight()); mBottomEdgeEffectActive = true; } if (!awakenScrollBars()) { invalidate(); } return true; } @Override public void onLongPress(MotionEvent e) { if (DEBUG) { Log.d(TAG, "onLongPress() y=" + mListY); } View child; for (int i = 0; i < getChildCount(); i++) { child = getChildAt(i); child.getHitRect(mClickedViewBounds); if (mClickedViewBounds.contains((int) e.getX(), (int) e.getY())) { if (!mIsActionMode) { mActionMode = startActionMode(mActionModeCallback); mIsActionMode = true; } if (!child.isSelected()) { mSelectedIds.add(mAdapter.getItemId(i)); child.setSelected(true); } else { mSelectedIds.remove(mAdapter.getItemId(i)); child.setSelected(false); } if (mSelectedIds.isEmpty()) { finishActionMode(); } invalidate(); return; } } } @Override public boolean onSingleTapUp(MotionEvent e) { if (DEBUG) { Log.d(TAG, "onSingleTapConfirmed() y=" + mListY); } View child; for (int i = 0; i < getChildCount(); i++) { child = getChildAt(i); child.getHitRect(mClickedViewBounds); if (mClickedViewBounds.contains((int) e.getX(), (int) e.getY())) { if (!mIsActionMode) { OnItemClickListener callback = getOnItemClickListener(); if (callback != null) { callback.onItemClick(ScheduleView.this, child, i, mAdapter.getItemId(i)); } } else { if (!child.isSelected()) { mSelectedIds.add(mAdapter.getItemId(i)); child.setSelected(true); } else { mSelectedIds.remove(mAdapter.getItemId(i)); child.setSelected(false); } if (mSelectedIds.isEmpty()) { finishActionMode(); } invalidate(); } break; } } return true; } }; mGestureDetector = new GestureDetector(context, mGestureListener); } }
From source file:com.javielinux.tweettopics2.TweetTopicsActivity.java
@Override public void onCreate(Bundle savedInstanceState) { try {// w ww . j ava 2s . c o m DataFramework.getInstance().open(this, Utils.packageName); } catch (Exception e) { e.printStackTrace(); } super.onCreate(savedInstanceState); CacheData.getInstance().fillHide(); ConnectionManager.getInstance().open(this); ConnectionManager.getInstance().loadUsers(); OnAlarmReceiver.callAlarm(this); if (PreferenceUtils.getFinishForceClose(this)) { PreferenceUtils.setFinishForceClose(this, false); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.title_crash); builder.setMessage(R.string.msg_crash); builder.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Utils.sendLastCrash(TweetTopicsActivity.this); } }); builder.setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); builder.create(); builder.show(); } Thread.UncaughtExceptionHandler currentHandler = Thread.getDefaultUncaughtExceptionHandler(); if (currentHandler != null) { Thread.setDefaultUncaughtExceptionHandler(new ErrorReporter(currentHandler, getApplication())); } if (PreferenceManager.getDefaultSharedPreferences(this).getString("prf_orientation", "2").equals("2")) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } // borrar notificaciones if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("prf_notif_delete_notifications_inside", true)) { ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).cancelAll(); } long goToColumnPosition = -1; int goToColumnType = -1; long goToColumnUser = -1; long goToColumnSearch = -1; long selectedTweetId = -1; Bundle extras = getIntent().getExtras(); if (extras != null) { if (extras.containsKey(KEY_EXTRAS_GOTO_COLUMN_POSITION)) { goToColumnPosition = extras.getLong(KEY_EXTRAS_GOTO_COLUMN_POSITION); } if (extras.containsKey(KEY_EXTRAS_GOTO_COLUMN_TYPE)) { goToColumnType = extras.getInt(KEY_EXTRAS_GOTO_COLUMN_TYPE); } if (extras.containsKey(KEY_EXTRAS_GOTO_COLUMN_USER)) { goToColumnUser = extras.getLong(KEY_EXTRAS_GOTO_COLUMN_USER); } if (extras.containsKey(KEY_EXTRAS_GOTO_COLUMN_SEARCH)) { goToColumnSearch = extras.getLong(KEY_EXTRAS_GOTO_COLUMN_SEARCH); } if (extras.containsKey(KEY_EXTRAS_GOTO_TWEET_ID)) { selectedTweetId = extras.getLong(KEY_EXTRAS_GOTO_TWEET_ID); } } int positionFromSensor = -1; if (savedInstanceState != null && savedInstanceState.containsKey(KEY_SAVE_STATE_COLUMN_POS)) { positionFromSensor = savedInstanceState.getInt(KEY_SAVE_STATE_COLUMN_POS); } Utils.createDirectoriesIfIsNecessary(); Display display = getWindowManager().getDefaultDisplay(); widthScreen = display.getWidth(); heightScreen = display.getHeight(); themeManager = new ThemeManager(this); themeManager.setTheme(); setContentView(R.layout.tweettopics_activity); fragmentAdapter = new TweetTopicsFragmentAdapter(this, getSupportFragmentManager()); pager = (ViewPager) findViewById(R.id.tweet_pager); pager.setAdapter(fragmentAdapter); indicator = (TitlePageIndicator) findViewById(R.id.tweettopics_bar_indicator); indicator.setFooterIndicatorStyle(TitlePageIndicator.IndicatorStyle.Triangle); indicator.setFooterLineHeight(0); indicator.setFooterColor(Color.WHITE); indicator.setClipPadding(-getWindowManager().getDefaultDisplay().getWidth()); indicator.setViewPager(pager); indicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int i, float v, int i1) { } @Override public void onPageSelected(int i) { reloadBarAvatar(); if (i == 0) { refreshMyActivity(); } } @Override public void onPageScrollStateChanged(int i) { } }); indicator.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { showActionBarColumns(); } }); findViewById(R.id.tweettopics_bar_my_activity).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { showActionBarIndicatorAndMovePager(0); } }); findViewById(R.id.tweettopics_bar_options).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { showMenuColumnsOptions(view); } }); layoutOptionsColumns = (LinearLayout) findViewById(R.id.tweettopics_ll_options_columns); layoutMainOptionsColumns = (LinearLayout) findViewById(R.id.tweettopics_ll_main_options_columns); layoutMainOptionsColumns.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { hideOptionsColumns(); } }); btnOptionsColumnsMain = (Button) findViewById(R.id.tweettopics_ll_options_columns_btn_main); btnOptionsColumnsMain.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { int pos = Integer.valueOf(view.getTag().toString()); Toast.makeText(TweetTopicsActivity.this, getString(R.string.column_main_message, fragmentAdapter.setColumnActive(pos)), Toast.LENGTH_LONG).show(); hideOptionsColumns(); } }); btnOptionsColumnsEdit = (Button) findViewById(R.id.tweettopics_ll_options_columns_btn_edit); btnOptionsColumnsEdit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { int pos = Integer.valueOf(view.getTag().toString()); EditColumnDialogFragment frag = new EditColumnDialogFragment( fragmentAdapter.getFragmentList().get(pos), new Callable() { @Override public Object call() throws Exception { refreshActionBarColumns(); return null; } }); frag.show(getSupportFragmentManager(), "dialog"); hideOptionsColumns(); } }); // cargar el popup de enlaces FrameLayout root = ((FrameLayout) findViewById(R.id.tweettopics_root)); popupLinks = new PopupLinks(this); popupLinks.loadPopup(root); splitActionBarMenu = new SplitActionBarMenu(this); splitActionBarMenu.loadSplitActionBarMenu(root); layoutBackgroundApp = (RelativeLayout) findViewById(R.id.tweettopics_layout_background_app); layoutBackgroundBar = (RelativeLayout) findViewById(R.id.tweettopics_bar_background); horizontalScrollViewColumns = (HorizontalScrollView) findViewById(R.id.tweettopics_bar_horizontal_scroll); layoutBackgroundColumnsBarContainer = (LinearLayout) findViewById(R.id.tweettopics_bar_columns_container); layoutBackgroundColumnsBar = (LinearLayout) findViewById(R.id.tweettopics_bar_columns); // layoutBackgroundColumnsBar.setCols(4); // // layoutBackgroundColumnsBar.setOnRearrangeListener(new OnRearrangeListener() { // public void onRearrange(int oldIndex, int newIndex) { // reorganizeColumns(oldIndex, newIndex); // } // // @Override // public void onStartDrag(int x, int index) { // showOptionsColumns(x, index, true); // } // // @Override // public void onMoveDragged(int index) { // hideOptionsColumns(); // } // // }); // layoutBackgroundColumnsBar.setOnItemClickListener(new AdapterView.OnItemClickListener() { // @Override // public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { // showActionBarIndicatorAndMovePager(position); // } // }); imgBarAvatar = (ImageView) findViewById(R.id.tweettopics_bar_avatar); imgBarAvatarBg = (ImageView) findViewById(R.id.tweettopics_bar_avatar_bg); imgBarCounter = (TextView) findViewById(R.id.tweettopics_bar_counter); imgNewStatus = (ImageView) findViewById(R.id.tweettopics_bar_new_status); imgNewStatus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { newStatus(); } }); imgBarAvatarGestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() { @Override public void onLongPress(MotionEvent e) { if (fragmentAdapter.instantiateItem(pager, pager.getCurrentItem()) instanceof BaseListFragment) { ((BaseListFragment) fragmentAdapter.instantiateItem(pager, pager.getCurrentItem())).goToTop(); } } @Override public boolean onDoubleTap(MotionEvent e) { if (fragmentAdapter.instantiateItem(pager, pager.getCurrentItem()) instanceof BaseListFragment) { ((BaseListFragment) fragmentAdapter.instantiateItem(pager, pager.getCurrentItem())).goToTop(); } return true; } @Override public boolean onSingleTapConfirmed(MotionEvent e) { animateDragged(); return true; } @Override public boolean onDown(MotionEvent e) { return true; } }); imgBarAvatarBg.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { return imgBarAvatarGestureDetector.onTouchEvent(motionEvent); } }); refreshTheme(); reloadBarAvatar(); refreshActionBarColumns(); if (goToColumnType >= 0) { if ((goToColumnType == TweetTopicsUtils.COLUMN_TIMELINE || goToColumnType == TweetTopicsUtils.COLUMN_MENTIONS || goToColumnType == TweetTopicsUtils.COLUMN_DIRECT_MESSAGES) && goToColumnUser >= 0) { openUserColumn(goToColumnUser, goToColumnType); } if (goToColumnType == TweetTopicsUtils.COLUMN_SEARCH && goToColumnSearch > 0) { openSearchColumn(new Entity("search", goToColumnSearch)); } } else if (goToColumnType == TweetTopicsUtils.COLUMN_MY_ACTIVITY) { } else if (goToColumnPosition > 0) { goToColumn((int) goToColumnPosition, false, selectedTweetId); } else if (positionFromSensor >= 0) { goToColumn(positionFromSensor, false, selectedTweetId); } else { int col = fragmentAdapter.getPositionColumnActive(); if (col > 0) goToColumn(col, false, selectedTweetId); } // comprobar si hay que proponer ir al market int access_count = PreferenceUtils.getApplicationAccessCount(this); if (access_count <= 20) { if (access_count == 20) { try { AlertDialog dialog = DialogUtils.RateAppDialogBuilder.create(this); dialog.show(); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } } PreferenceUtils.setApplicationAccessCount(this, access_count + 1); } PreferenceUtils.showChangeLog(this, true); }