Java Code Examples for android.support.v7.widget.RecyclerView#setOnTouchListener()
The following examples show how to use
android.support.v7.widget.RecyclerView#setOnTouchListener() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DisplayManager.java From SoloPi with Apache License 2.0 | 6 votes |
/** * 提供主界面 * @param context * @return */ private View provideMainView(Context context) { if (runningMode == DisplayProvider.RECORDING_MODE) { return null; } floatWinList = (RecyclerView) LayoutInflater.from(context).inflate(R.layout.display_main_layout, null); floatWinList.setLayoutManager(new LinearLayoutManager(context)); floatWinList.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return false; } }); floatWinAdapter = new FloatWinAdapter(context, this, currentDisplayInfo); floatWinList.setAdapter(floatWinAdapter); // 添加分割线 floatWinList.addItemDecoration(new RecycleViewDivider(context, LinearLayoutManager.HORIZONTAL, 1, context.getResources().getColor(R.color.divider_color))); return floatWinList; }
Example 2
Source File: VoiceSettingsSwipeController.java From your-local-weather with GNU General Public License v3.0 | 6 votes |
private void setTouchListener(final Canvas c, final RecyclerView recyclerView, final RecyclerView.ViewHolder viewHolder, final float dX, final float dY, final int actionState, final boolean isCurrentlyActive) { recyclerView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { swipeBack = event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP; if (swipeBack) { if (dX < -buttonWidth) buttonShowedState = ButtonsState.RIGHT_VISIBLE; else if (dX > buttonWidth) buttonShowedState = ButtonsState.LEFT_VISIBLE; if (buttonShowedState != ButtonsState.GONE) { setTouchDownListener(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); setItemsClickable(recyclerView, false); } } return false; } }); }
Example 3
Source File: WeatherForecastActivity.java From your-local-weather with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); initializeWeatherForecastReceiver(UpdateWeatherService.ACTION_FORECAST_UPDATE_RESULT); setContentView(R.layout.activity_weather_forecast); mRecyclerView = (RecyclerView) findViewById(R.id.forecast_recycler_view); mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); localityView = (TextView) findViewById(R.id.forecast_locality); visibleColumns = AppPreference.getForecastActivityColumns(this); connectionDetector = new ConnectionDetector(WeatherForecastActivity.this); forecastType = (Switch) findViewById(R.id.forecast_forecastType); forecastType.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { AppPreference.setForecastType(getBaseContext(), isChecked ? 2 : 1); updateUI(); } }); updateUI(); mRecyclerView.setOnTouchListener(new ActivityTransitionTouchListener( MainActivity.class, GraphsActivity.class, this)); }
Example 4
Source File: LocationsSwipeController.java From your-local-weather with GNU General Public License v3.0 | 6 votes |
private void setTouchListener(final Canvas c, final RecyclerView recyclerView, final RecyclerView.ViewHolder viewHolder, final float dX, final float dY, final int actionState, final boolean isCurrentlyActive) { recyclerView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { swipeBack = event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP; if (swipeBack) { if (dX < -buttonWidth) buttonShowedState = ButtonsState.RIGHT_VISIBLE; else if (dX > buttonWidth) buttonShowedState = ButtonsState.LEFT_VISIBLE; if (buttonShowedState != ButtonsState.GONE) { setTouchDownListener(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); setItemsClickable(recyclerView, false); } } return false; } }); }
Example 5
Source File: MessageSearchFragment.java From talk-android with MIT License | 6 votes |
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false)); recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setAdapter(adapter); recyclerView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP && recyclerViewState == RecyclerView.SCROLL_STATE_IDLE) { getActivity().getSupportFragmentManager() .beginTransaction() .setCustomAnimations(R.anim.anim_fade_in, R.anim.anim_fade_out) .remove(MessageSearchFragment.this) .commit(); if (listener != null) { listener.onRemoveFragment(); } } return false; } }); recyclerView.addOnScrollListener(scrollListener); }
Example 6
Source File: SearchStaticRecyclerFragment.java From Search-View-Layout with Apache License 2.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_search_static_recycler, container, false); RecyclerView recyclerView = ((RecyclerView) rootView.findViewById(R.id.search_static_recycler)); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); ArrayList<String> strings = new ArrayList<>(); for (int i = 0; i < 10; i++) { strings.add(i+" -- \n"+getString(R.string.lorem_1)); } ListViewAdapter adapter = new ListViewAdapter(strings); recyclerView.setAdapter(adapter); recyclerView.setOnTouchListener(new View.OnTouchListener() { // Setting on Touch Listener for handling the touch inside ScrollView @Override public boolean onTouch(View v, MotionEvent event) { // Disallow the touch request for parent scroll on touch of child view v.getParent().requestDisallowInterceptTouchEvent(true); return false; } }); return rootView; }
Example 7
Source File: FindListFragment.java From school_shop with MIT License | 6 votes |
private void initView() { pubBtn = (FloatingActionButton) mView.findViewById(R.id.find_list_floatButton); recyclerView = (RecyclerView) mView.findViewById(R.id.find_list_recyclerView); swipeRefreshLayout = (SwipeRefreshLayout) mView.findViewById(R.id.find_list_swipeRefreshLayout); init(); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity()); recyclerView.setLayoutManager(linearLayoutManager); recyclerView.setItemAnimator(new DefaultItemAnimator()); loadData(); swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh() { } }); pubBtn.setColor(getResources().getColor(R.color.statusbar_bg)); pubBtn.setOnClickListener(this); recyclerView.setOnTouchListener(new ShowHideOnScroll(pubBtn)); }
Example 8
Source File: VoiceSettingsSwipeController.java From your-local-weather with GNU General Public License v3.0 | 5 votes |
private void setTouchDownListener(final Canvas c, final RecyclerView recyclerView, final RecyclerView.ViewHolder viewHolder, final float dX, final float dY, final int actionState, final boolean isCurrentlyActive) { recyclerView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { setTouchUpListener(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); } return false; } }); }
Example 9
Source File: LocationsSwipeController.java From your-local-weather with GNU General Public License v3.0 | 5 votes |
private void setTouchDownListener(final Canvas c, final RecyclerView recyclerView, final RecyclerView.ViewHolder viewHolder, final float dX, final float dY, final int actionState, final boolean isCurrentlyActive) { recyclerView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { setTouchUpListener(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); } return false; } }); }
Example 10
Source File: ContentFragment.java From VerticalViewPager with MIT License | 5 votes |
private void initRecyclerView(View view) { RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.content_list); recyclerView.setOnTouchListener(new VerticalVPOnTouchListener((DummyViewPager) getArguments().getSerializable("viewpager")));//set the vertical scroll controller recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); recyclerView.setAdapter(new ContentAdapter(getPosition())); }
Example 11
Source File: CardSnapHelper.java From CardLayoutManager with Apache License 2.0 | 5 votes |
@Override public void attachToRecyclerView(@Nullable RecyclerView recyclerView) throws IllegalStateException { super.attachToRecyclerView(recyclerView); if (recyclerView != null) { recyclerView.setOnTouchListener(this); } }
Example 12
Source File: BindSuperAdapter.java From LazyRecyclerAdapter with MIT License | 5 votes |
@Override public void onAttachedToRecyclerView(RecyclerView recyclerView) { super.onAttachedToRecyclerView(recyclerView); RecyclerView.Adapter adapter = recyclerView.getAdapter(); mRecyclerView = recyclerView; if (adapter instanceof BindSuperAdapter) { mWrapAdapter = new WrapAdapter((BindSuperAdapter) adapter); recyclerView.setAdapter(mWrapAdapter); recyclerView.setOnTouchListener(this); recyclerView.addOnScrollListener(mScrollListener); adapter.registerAdapterDataObserver(mDataObserver); mDataObserver.onChanged(); } }
Example 13
Source File: RecyclerViewActivity.java From Rocko-Android-Demos with Apache License 2.0 | 5 votes |
private void init() { recyclerView = (RecyclerView) findViewById(R.id.recyler_view); linearLayoutManager = new LinearLayoutManager(this); linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); staggeredGridLayoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL); recyclerView.setLayoutManager(linearLayoutManager); recyclerView.setAdapter(new SimpleRecylerViewAdapter(this, getData(100))); AutoScrollHelper autoScrollHelper = new RecyclerViewAutoScrollHelper(recyclerView); autoScrollHelper.setEnabled(true); recyclerView.setOnTouchListener(autoScrollHelper); }
Example 14
Source File: ShareMessageFragment.java From TestChat with Apache License 2.0 | 4 votes |
@Override public void initView() { display = (RecyclerView) findViewById(R.id.rcv_share_fragment_display); refresh = (SwipeRefreshLayout) findViewById(R.id.refresh_share_fragment_refresh); bottomInput = (LinearLayout) findViewById(R.id.ll_share_fragment_bottom); send = (ImageView) findViewById(R.id.iv_share_fragment_send); container = (RelativeLayout) findViewById(R.id.rl_share_fragment_container); mMenu = (FloatingActionsMenu) findViewById(R.id.fam_share_message_menu); normal = (FloatingActionButton) findViewById(R.id.fab_share_message_normal); video = (FloatingActionButton) findViewById(R.id.fab_share_message_video); input = (EditText) findViewById(R.id.et_share_fragment_input); image = (FloatingActionButton) findViewById(R.id.fab_share_message_image); container.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { Rect rect = new Rect(); container.getWindowVisibleDisplayFrame(rect); screenHeight = container.getRootView().getHeight(); int keyBoardHeight = screenHeight - rect.bottom; if (keyBoardHeight != mKeyBoardHeight) { if (keyBoardHeight > mKeyBoardHeight) { bottomInput.setVisibility(View.VISIBLE); mMenu.setVisibility(View.GONE); mKeyBoardHeight = keyBoardHeight; mLinearLayoutManager.scrollToPositionWithOffset(currentPosition, getListOffset()); } else { mKeyBoardHeight = keyBoardHeight; mMenu.setVisibility(View.VISIBLE); bottomInput.setVisibility(View.GONE); } } } }); send.setOnClickListener(this); normal.setOnClickListener(this); video.setOnClickListener(this); image.setOnClickListener(this); display.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (mCommentPopupWindow != null && mCommentPopupWindow.isShowing()) { mCommentPopupWindow.dismiss(); } if (mMenu.isExpanded()) { mMenu.collapse(); } LogUtil.e("container:onTouch"); // 这里进行点击关闭编辑框 if (bottomInput.getVisibility() == View.VISIBLE) { LogUtil.e("触摸界面点击关闭输入法"); dealBottomView(false); return true; } return false; } }); refresh.setOnRefreshListener(mOnRefreshListener = new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { // 数据量比较小,进行延时,2秒后再进行加载 new Handler().postDelayed(new Runnable() { @Override public void run() { SharedMessage shareMessage = mAdapter.getData(0); LogUtil.e("下拉加载的前一个说说消息为1"); if (shareMessage == null) { LogUtil.e("首次加载数据"); loadData(true, "0000-00-00 01:00:00"); } else { LogUtil.e(shareMessage); loadData(true, shareMessage.getCreatedAt()); } } }, 2000); } }); display.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); // 这里进行重发,如果在滚动的时候就不进行数据的加载和视图的显示 if (newState == RecyclerView.SCROLL_STATE_IDLE) { LogUtil.e("休闲的时候进行加载"); Glide.with(getActivity()).resumeRequests(); } else { LogUtil.e("滚动的时候不进行加载"); Glide.with(getActivity()).pauseRequests(); } } }); }
Example 15
Source File: RecyclerViewFragment.java From Bounce with Apache License 2.0 | 4 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = inflater.inflate(R.layout.fragment_recycler_view, container, false); maxSunTranslation = -(int) (getResources().getDimension(R.dimen.header_height) * .25f); main = root.findViewById(R.id.main); sun = (ImageView) root.findViewById(R.id.sun_image_view); header = root.findViewById(R.id.header_image_view); headerOverlay = root.findViewById(R.id.header_overlay); header.setPivotX(Utils.getScreenWidth(getActivity()) * .5f); header.setPivotY(getResources().getDimension(R.dimen.header_height)); headerOverlay.setPivotX(header.getPivotX()); headerOverlay.setPivotY(header.getPivotY()); headerOverlay.setAlpha(0); headerHeight = (int) getResources().getDimension(R.dimen.header_height); recyclerView = (RecyclerView) root.findViewById(R.id.recycler_view); recyclerView.setAdapter(new DemoAdapter()); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); recyclerView.setPivotX(Utils.getScreenWidth(getActivity())); recyclerView.addOnScrollListener(onScrollListener); bounceTouchListener = BounceTouchListener.create(recyclerView, new BounceTouchListener.OnTranslateListener() { @Override public void onTranslate(float translation) { if (translation > 0) { sun.setTranslationY(Math.max(maxSunTranslation, -translation)); sun.setAlpha(Math.min(1, translation / getResources().getDimension(R.dimen.options_pad))); bounceTouchListener.setMaxAbsTranslation(-99); header.setRotationX(Math.min((float) Math.pow(translation, .55), 90)); header.setTranslationY(translation); headerOverlay.setRotationX(header.getRotationX()); headerOverlay.setTranslationY(header.getTranslationY()); headerOverlay.setAlpha(Math.min(.4f, translation / -(float) maxSunTranslation)); main.setBackgroundColor((int) argbEvaluator.evaluate(Math.min(1, translation / -(float) maxSunTranslation), dayColor, nightColor)); } else { main.setBackgroundColor(getResources().getColor(R.color.grey)); } } }); recyclerView.setOnTouchListener(bounceTouchListener); return root; }