private void initFloatingActionButton() { FloatingActionButton fab = (FloatingActionButton) getActivity().findViewById(R.id.fab); if (fab != null) { if (isMyAccount()) { // Own log, button opens window to add training fab.setVisibility(View.VISIBLE); fab.setImageResource(R.drawable.ic_playlist_add); fab.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Activity activity = getActivity(); Fragment fragment = TrainingFragment.newInstance(); FragmentTransaction transaction = activity.getFragmentManager().beginTransaction(); transaction.replace(R.id.fragment_container, fragment); transaction.addToBackStack(null); transaction.commit(); } }); } else { // Someone else's log, button opens window to add comment // TODO fab.setVisibility(View.GONE); } } }
@SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { int id = item.getItemId(); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setVisibility(View.VISIBLE); if (id == R.id.nav_my_collection) { databaseTable = "records"; customAdapter.isOnLendoutScreen = false; reloadListView(); getSupportActionBar().setTitle("My Collection"); changeActionBarColor("#1c2f2f"); } else if (id == R.id.nav_wishlist) { databaseTable = "wishlist"; customAdapter.isOnLendoutScreen = false; reloadListView(); getSupportActionBar().setTitle("Wishlist"); changeActionBarColor("#2f1c2f"); } else if (id == R.id.nav_backup) { Intent open_BackupMenu = new Intent(MainActivity.this, BackupRestore.class); startActivity(open_BackupMenu); } else if (id == R.id.nav_lentout) { databaseTable = "lentout"; reloadListView(); fab.setVisibility(View.GONE); getSupportActionBar().setTitle("Lentout"); changeActionBarColor("#2f2f1c"); } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }
@SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); fab.setVisibility(View.VISIBLE); if (id == R.id.nav_camera) { // set the fragment initially MainFragment fragment = new MainFragment(); android.support.v4.app.FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); fragmentTransaction.replace(R.id.fragment_container, fragment); fragmentTransaction.commit(); // handle the camera action } else if (id == R.id.nav_gallery) { Zakkaartjes fragment = new Zakkaartjes(); android.support.v4.app.FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); fragmentTransaction.replace(R.id.fragment_container, fragment); fragmentTransaction.commit(); } else if (id == R.id.nav_slideshow) { Rekenen fragment = new Rekenen(); android.support.v4.app.FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); fragmentTransaction.replace(R.id.fragment_container, fragment); fragmentTransaction.commit(); } else if (id == R.id.nav_manage) { // Intent intent = new Intent(this, Notities.class); // startActivity(intent); // finish(); fab.setVisibility(View.GONE); NotitiesFragment fragment = new NotitiesFragment(); android.support.v4.app.FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); fragmentTransaction.replace(R.id.fragment_container, fragment); fragmentTransaction.commit(); } else if (id == R.id.nav_share) { Handelingen fragment = new Handelingen(); android.support.v4.app.FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); fragmentTransaction.replace(R.id.fragment_container, fragment); fragmentTransaction.commit(); } else if (id == R.id.nav_send) { Intent emailIntent = new Intent( Intent.ACTION_SENDTO, Uri.fromParts("mailto", "*****@*****.**", null)); emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Email van verpleegkundig zakboek app"); startActivity(Intent.createChooser(emailIntent, "Verzend e-mail")); } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }
@Override protected void onResume() { super.onResume(); if (V2EX.getInstance().isLogin()) { floatingActionButton.setVisibility(View.VISIBLE); } else { floatingActionButton.setVisibility(View.INVISIBLE); } }
@Override public void onClick(View view) { int id = view.getId(); if (id == R.id.fbReleaseTaxi) driverRating.show(getFragmentManager(), "Rate the Driver"); else if (id == R.id.fbWaitingState) { fbReleaseTaxi.setVisibility(View.VISIBLE); fbWaitingState.setVisibility(View.INVISIBLE); serverCommunicator.startRide(driverId); } }
/** * 重载父类实现的 EventBus 订阅方法,实现更具体的逻辑处理 * * @param event 订阅的消息类型 */ @Override public void onEventBus(MLConnectionEvent event) { /** 因为3.x的sdk断开服务器连接后会一直重试并发出回调,所以为了防止一直Toast提示用户, 这里取消弹出 Toast 方式,只是显示图标 */ if (event.getType() == MLConstants.ML_CONNECTION_CONNECTED) { mConnectionFabBtn.setImageResource(R.mipmap.ic_signal_wifi_on_white_24dp); mConnectionFabBtn.setVisibility(View.GONE); } else { mConnectionFabBtn.setImageResource(R.mipmap.ic_signal_wifi_off_white_24dp); mConnectionFabBtn.setVisibility(View.VISIBLE); } super.onEventBus(event); }
@Override protected void onResume() { super.onResume(); isOnride = sharedPreferences.getBoolean(IS_ON_RIDE, false); if (isOnride) { fbReleaseTaxi.setVisibility(View.VISIBLE); fbWaitingState.setVisibility(View.INVISIBLE); } else { fbReleaseTaxi.setVisibility(View.INVISIBLE); fbWaitingState.setVisibility(View.VISIBLE); } }
/** 界面初始化操作 */ private void init() { mActivity = this; if (EMClient.getInstance().isConnected()) { mConnectionFabBtn.setImageResource(R.mipmap.ic_signal_wifi_on_white_24dp); mConnectionFabBtn.setVisibility(View.GONE); } else { mConnectionFabBtn.setImageResource(R.mipmap.ic_signal_wifi_off_white_24dp); mConnectionFabBtn.setVisibility(View.VISIBLE); } setSupportActionBar(getToolbar()); getSupportActionBar().setTitle(R.string.ml_chat); }
private void showFb() { if (mScrollToTopFb.getVisibility() == View.VISIBLE) { return; } mScrollToTopFb.setVisibility(View.VISIBLE); mScrollToTopFb.startAnimation(mFbInAnim); }
private void hideFb() { if (mScrollToTopFb.getVisibility() != View.VISIBLE) { return; } mScrollToTopFb.startAnimation(mFbOutAnim); mScrollToTopFb.setVisibility(View.INVISIBLE); }
private void initLayout() { setContentView(R.layout.activity_debt); mFab = (FloatingActionButton) findViewById(R.id.fab); mFab.setVisibility(mSavedStateIsPlaying ? View.GONE : View.VISIBLE); mFab.setOnClickListener(this); mFab.animate().scaleX(1).scaleY(1).setInterpolator(mInterpolator).setStartDelay(400).start(); }
// Same animation that FloatingActionButton.Behavior uses to show the FAB when the AppBarLayout // enters private void animateIn(FloatingActionButton button) { button.setVisibility(View.VISIBLE); Animation anim = AnimationUtils.loadAnimation(button.getContext(), R.anim.abc_slide_in_bottom); anim.setDuration(600L); anim.setInterpolator(INTERPOLATOR); button.startAnimation(anim); }
@Override protected void onCreate(Bundle savedInstanceState) { if (getIntent().hasExtra(ARG_PARENT_CATEGORY_STYLE)) { int styleResId = getIntent().getIntExtra(ARG_PARENT_CATEGORY_STYLE, -1); if (styleResId > 0) { setTheme(styleResId); } } super.onCreate(savedInstanceState); mParentCategoryId = getIntent().getLongExtra(ARG_PARENT_CATEGORY_ID, 0); if (mParentCategoryId == 0) { Intent categoryIntent = new Intent(this, CategoriesActivity.class); startActivity(categoryIntent); } setContentView(R.layout.app_bar); ViewStub mainContent = (ViewStub) findViewById(R.id.main_content); mainContent.setLayoutResource(R.layout.content_fragment); mainContent.inflate(); mAppBarLayout = (AppBarLayout) findViewById(R.id.app_bar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowTitleEnabled(false); } getSupportLoaderManager().initLoader(0, null, this); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { Intent newCategoryIntent = new Intent(SubcategoriesActivity.this, ManageCategoryActivity.class); newCategoryIntent.putExtra( ManageCategoryActivity.ARG_PARENT_CATEGORY_ID, mParentCategoryId); startActivity(newCategoryIntent); } }); fab.setVisibility(View.VISIBLE); if (savedInstanceState == null) { CategoriesFragment fragment = CategoriesFragment.newInstance(mParentCategoryId); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.add(R.id.fragment, fragment); transaction.commit(); } }
/** To hide fab, you need to remove its anchor */ private void hideFab() { // Ugly bug makes the view go to bottom|center of screen before hiding, seems like you need to // implement your own fab behavior... fabPhoto.setVisibility(View.GONE); final CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) fabPhoto.getLayoutParams(); layoutParams.setAnchorId(View.NO_ID); fabPhoto.requestLayout(); fabPhoto.hide(); }
private void initView() { type = getIntent().getExtras().getInt(TYPE); info.setId(getIntent().getExtras().getInt(USER_ID)); nickname.setText(""); email.setText(""); work.setText(""); sign.setText(""); birth.setText(""); sex.setBackground(getResources().getDrawable(R.drawable.ic_sex_boy)); location.setText(""); followNum.setText(""); focusNum.setText(""); DataPresenter.requestUserInfoById(info.getId(), UserInfoActivity.this); if (type == TYPE_CURR_USER) { currUserFab.setVisibility(View.VISIBLE); btnFollow.setVisibility(View.GONE); } else if (type == TYPE_OTHER_USER) { otherUserFab.setVisibility(View.VISIBLE); btnFollow.setVisibility(View.VISIBLE); DataPresenter.requestFriendList(info.getId(), UserInfoActivity.this); } currUserFab.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { EditUserInfoActivity.actionStart(UserInfoActivity.this); } }); otherUserFab.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { MessageActivity.actionStart(UserInfoActivity.this, info.getUsername()); } }); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = super.onCreateView(inflater, container, savedInstanceState); if (mRoot) { mAddDirectoryFAB = (FloatingActionButton) v.findViewById(R.id.fab_add_custom_dir); mAddDirectoryFAB.setVisibility(View.VISIBLE); mAddDirectoryFAB.setOnClickListener(this); } return v; }
@Override public void showFab(boolean show) { if (show) { fabSubscription = RxViewAnimation.animate(fab, R.anim.fade_in) .subscribe( viewAnimationEvent -> { fab.setVisibility(VISIBLE); fabShown = true; }); } else { fabSubscription = RxViewAnimation.animate(fab, R.anim.fade_out) .subscribe( viewAnimationEvent -> { fab.setVisibility(INVISIBLE); fabShown = false; }); } }
@Override public void onDetach() { button.setClickable(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Animator anim = ViewAnimationUtils.createCircularReveal( thirdView, thirdView.getWidth() / 2, thirdView.getHeight() / 2, 0, thirdView.getHeight()) .setDuration(450); thirdView.setVisibility(View.VISIBLE); anim.start(); } else { thirdView.setVisibility(View.VISIBLE); } super.onDetach(); }
@Override public void onAttach(final Activity activity) { super.onAttach(activity); // Activities containing this fragment must implement its callbacks. if (!(activity instanceof Callbacks)) { throw new IllegalStateException("Activity must implement fragment's callbacks."); } mCallbacks = (Callbacks) activity; if (fab != null) { fab.setVisibility(mCallbacks.hasFab() ? View.VISIBLE : View.GONE); } }
@Override public View onCreateView( final LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.generic_list_fragment, container, false); listView = (RecyclerView) rootView.findViewById(R.id.generic_list); fab = (FloatingActionButton) rootView.findViewById(R.id.fabbutton); fab.setOnClickListener(this); fab.setVisibility(mCallbacks.hasFab() ? View.VISIBLE : View.GONE); if (!(mCallbacks.getAdapter(this) instanceof SettingsGroupAdapter)) { listView.addItemDecoration( new DividerItemDecoration(rootView.getContext(), null, false, false)); } return rootView; }
// if sdk < 14, just ignore because of min sdk is 14 private void animateIn(FloatingActionButton button) { button.setVisibility(View.VISIBLE); if (Build.VERSION.SDK_INT >= 14) { ViewCompat.animate(button) .scaleX(1.0F) .scaleY(1.0F) .alpha(1.0F) .translationY(0) .setInterpolator(INTERPOLATOR) .withLayer() .setListener(null) .start(); } }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mDevices = ((MainActivity) getActivity()).getDevices(); mNetworks = ((MainActivity) getActivity()).getNetworks(); mDetailViewVisible = false; mNetworkLabels = new ArrayList<>(); mDevicesList = new List[5]; mView = inflater.inflate(R.layout.fragment_overview, container, false); mSpeedTestFab = (FloatingActionButton) mView.findViewById(R.id.fab); mSpeedTestFab.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(getActivity(), SpeedTestActivity.class); getActivity().startActivityForResult(intent, 0); } }); mSpeedTestFab.setVisibility(View.INVISIBLE); mDetailView = (LinearLayout) mView.findViewById(R.id.detail_layout); mWifiMessage = (TextView) mView.findViewById(R.id.wifi_message); mStatusMessage = (TextView) mView.findViewById(R.id.status_message); mDevicesMessage = new TextView[] { (TextView) mView.findViewById(R.id.devices), (TextView) mView.findViewById(R.id.are_connected) }; mNetworkIcons = new TextView[] { (TextView) mView.findViewById(R.id.lan_0), (TextView) mView.findViewById(R.id.lan_1), (TextView) mView.findViewById(R.id.lan_2), (TextView) mView.findViewById(R.id.lan_3), (TextView) mView.findViewById(R.id.lan_4) }; mNetworkLines = new View[] { mView.findViewById(R.id.lan_0_l), mView.findViewById(R.id.lan_1_l), mView.findViewById(R.id.lan_2_l), mView.findViewById(R.id.lan_3_l), mView.findViewById(R.id.lan_4_l) }; initialize(); mListener.onSignal(SIGNAL_LOADED, null); return mView; }
public void showFab() { mFab.setVisibility(View.VISIBLE); mFab.setScaleX(0.65f); mFab.setScaleY(0.65f); mFab.animate().scaleX(1f).scaleY(1f).setDuration(100).setListener(null); mFab.setImageDrawable( new AnimatingDrawable.Builder(getBaseContext()) .frames( R.drawable.fab_open_1, R.drawable.fab_open_2, R.drawable.fab_open_3, R.drawable.fab_open_4, R.drawable.fab_open_5) .build()); ((Animatable) mFab.getDrawable()).start(); }
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); if (savedInstanceState != null) { // TODO save } mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.layout_swipe_refresh); mSwipeRefreshLayout.setOnRefreshListener(this); mSwipeRefreshLayout.setColorSchemeResources( R.color.indicator_red, R.color.indicator_green, R.color.indicator_blue, R.color.indicator_orange); mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view); mAdapter = new TwitterFeedRecyclerAdapter(mTweetList); mAdapter.setOnClickTweetListener(mOnClickTweetListener); mAdapter.setOnClickMoreButtonListener( new View.OnClickListener() { @Override public void onClick(View v) { if (mOnClickTweetListener != null) { mOnClickTweetListener.onClickMoreButton(); } } }); mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity())); mRecyclerView.setAdapter(mAdapter); FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.floating_action_button); fab.setVisibility(View.VISIBLE); fab.setBackgroundTintList( ColorStateList.valueOf(getResources().getColor(R.color.background_fab_gray_blue))); fab.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (mOnClickTweetListener != null) { mOnClickTweetListener.onClickPostTweet(); } } }); }
// Same animation that FloatingActionButton.Behavior uses to show the FAB when the AppBarLayout // enters private void animateIn(FloatingActionButton button) { button.setVisibility(View.VISIBLE); if (Build.VERSION.SDK_INT >= 14) { ViewCompat.animate(button) .scaleX(1.0F) .scaleY(1.0F) .alpha(1.0F) .setInterpolator(INTERPOLATOR) .withLayer() .setListener(null) .start(); } else { Animation anim = AnimationUtils.loadAnimation(button.getContext(), android.R.anim.fade_in); anim.setDuration(200L); anim.setInterpolator(INTERPOLATOR); button.startAnimation(anim); } }
protected void myOnAttach(Context context) { android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) getActivity().findViewById(R.id.toolbar); AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams(); // Salvo gli scrollFlags originali per poterli ripristinare nell'onDetach scrollFlags = params.getScrollFlags(); params.setScrollFlags(0); ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle("Search students"); /* //SE SI VUOLE MOSTRARE IL TABLAYOUT TabLayout tabLayout = (TabLayout) getActivity().findViewById(R.id.tabs); tabLayout.setVisibility(View.VISIBLE); // SE SI VUOLE MODIFICARE IL app:layout_behavior del FrameLayout if(behavior != null) return; FrameLayout layout =(FrameLayout) getActivity().findViewById(R.id.frame); CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) layout.getLayoutParams(); behavior = params.getBehavior(); params.setBehavior(null); */ FloatingActionButton fab = (FloatingActionButton) getActivity().findViewById(R.id.fab); fab.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) {} }); fab.setVisibility(View.GONE); }
/** Hide progress bar and show layout */ private void hideProgressBar() { mProgressBar.setVisibility(View.GONE); mRecyclerView.setVisibility(View.VISIBLE); mFAB.setVisibility(View.VISIBLE); }
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); final Bundle arguments = getArguments(); final boolean showActionDrawerToggle = arguments == null ? DEFAULT_SHOW_ACTION_DRAWER_TOGGLE : arguments.getBoolean( EXTRA_SHOW_ACTION_DRAWER_TOGGLE, DEFAULT_SHOW_ACTION_DRAWER_TOGGLE); actionbarShadow = view.findViewById(R.id.actionbar_shadow); final FragmentManager fm = getChildFragmentManager(); mSlidingPanel = (SlidingUpPanelLayout) view.findViewById(R.id.slidingPanelContainer); mSlidingPanel.addPanelSlideListener(slidingPanelListenerMgr); warningText = (TextView) view.findViewById(R.id.failsafeTextView); warningContainer = view.findViewById(R.id.warningContainer); ImageView closeWarningView = (ImageView) view.findViewById(R.id.close_warning_view); closeWarningView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { hideWarningView(); } }); setupMapFragment(); mGoToMyLocation = (FloatingActionButton) view.findViewById(R.id.my_location_button); mGoToDroneLocation = (FloatingActionButton) view.findViewById(R.id.drone_location_button); actionDrawerToggle = (FloatingActionButton) view.findViewById(R.id.toggle_action_drawer); if (showActionDrawerToggle) { actionDrawerToggle.setVisibility(View.VISIBLE); actionDrawerToggle.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (navActivity == null) return; if (navActivity.isActionDrawerOpened()) navActivity.closeActionDrawer(); else navActivity.openActionDrawer(); } }); } mGoToMyLocation.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (mapFragment != null) { mapFragment.goToMyLocation(); updateMapLocationButtons(AutoPanMode.DISABLED); } } }); mGoToMyLocation.setOnLongClickListener( new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { if (mapFragment != null) { mapFragment.goToMyLocation(); updateMapLocationButtons(AutoPanMode.USER); return true; } return false; } }); mGoToDroneLocation.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (mapFragment != null) { mapFragment.goToDroneLocation(); updateMapLocationButtons(AutoPanMode.DISABLED); } } }); mGoToDroneLocation.setOnLongClickListener( new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { if (mapFragment != null) { mapFragment.goToDroneLocation(); updateMapLocationButtons(AutoPanMode.DRONE); return true; } return false; } }); flightActions = (FlightControlManagerFragment) fm.findFragmentById(R.id.flightActionsFragment); if (flightActions == null) { flightActions = new FlightControlManagerFragment(); fm.beginTransaction().add(R.id.flightActionsFragment, flightActions).commit(); } // Add the mode info panel fragment FlightModePanel flightModePanel = (FlightModePanel) fm.findFragmentById(R.id.sliding_drawer_content); if (flightModePanel == null) { flightModePanel = new FlightModePanel(); fm.beginTransaction().add(R.id.sliding_drawer_content, flightModePanel).commit(); } }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.lay_fragpayable, container, false); recyclerView = (RecyclerView) rootView.findViewById(R.id.recycleviewPay); layoutNoContent = (LinearLayout) rootView.findViewById(R.id.layoutNoContent); FloatingActionsMenu actionsMenu = (FloatingActionsMenu) getActivity().findViewById(R.id.multiple_actions); actionsMenu.setVisibility(View.GONE); FloatingActionButton fab = (FloatingActionButton) getActivity().findViewById(R.id.fab); fab.setVisibility(View.VISIBLE); fab.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(getActivity(), manage_bill.class); intent.putExtra(AppConfig.BILL_ID, billId); startActivity(intent); } }); // Recycleview onitem touch recyclerView.addOnItemTouchListener( new RecyclerView.OnItemTouchListener() { @Override public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) { View child = recyclerView.findChildViewUnder(e.getX(), e.getY()); if (child != null && mGestureDetector.onTouchEvent(e)) { onItemClick(child); return true; } return false; } @Override public void onTouchEvent(RecyclerView rv, MotionEvent e) {} @Override public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {} }); // recicleview onswipe final SimpleCallback simpleItemTouchCallback = new SimpleCallback(0, LEFT | RIGHT) { @Override public boolean onMove( RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { return false; } @Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) { onSwipeDelete(viewHolder, rootView); } }; mOnClickListener = new View.OnClickListener() { @Override public void onClick(View view) { restoreBill(); Snackbar snackbar1 = Snackbar.make(rootView, AppConfig.BILL_RESTORED, Snackbar.LENGTH_SHORT); snackbar1.show(); } }; ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback); itemTouchHelper.attachToRecyclerView(recyclerView); loadBills(); return rootView; }
private void showFragment( String prefTag, int itemId, String actionBarTitle, String fragmentTagShow, String fragmentTagHide) { android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); assert getSupportActionBar() != null; // We always have an ActionBar available, so this stops Android Studio from // complaining about possible NullPointerExceptions // Setup alt text view TextView tvAlt = (TextView) findViewById(R.id.tvAlt); tvAlt.setVisibility(View.GONE); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) tvAlt.getLayoutParams(); int dpMargin = 5; float d = this.getResources().getDisplayMetrics().density; int margin = (int) (dpMargin * d); // Setup FAB if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(prefTag, false)) { params.setMargins(margin, margin, margin, margin); mFab.setVisibility(View.GONE); } else { int dpMarginRight = 50; int marginRight = (int) (dpMarginRight * d); params.setMargins(margin, margin, marginRight, margin); mFab.setVisibility(View.VISIBLE); } getSupportActionBar().setTitle(actionBarTitle); if (fragmentManager.findFragmentByTag(fragmentTagShow) != null) { // if the fragment exists, show it. fragmentManager .beginTransaction() .show(fragmentManager.findFragmentByTag(fragmentTagShow)) .commitAllowingStateLoss(); // Update action bar if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("pref_subtitle", true)) { switch (itemId) { // Update Action Bar title case R.id.nav_favorites: { getSupportActionBar() .setSubtitle( String.valueOf( FavoritesFragment.sFavorites[FavoritesFragment.sFavoriteIndex])); break; } case R.id.nav_browser: { getSupportActionBar() .setSubtitle(String.valueOf(ComicBrowserFragment.sLastComicNumber)); break; } } } } else { // if the fragment does not exist, add it to fragment manager. switch (itemId) { case R.id.nav_favorites: { fragmentManager .beginTransaction() .add(R.id.flContent, new FavoritesFragment(), fragmentTagShow) .commitAllowingStateLoss(); break; } case R.id.nav_browser: { fragmentManager .beginTransaction() .add(R.id.flContent, new ComicBrowserFragment(), fragmentTagShow) .commitAllowingStateLoss(); } } } // if the other fragment is visible, hide it. if (fragmentManager.findFragmentByTag(fragmentTagHide) != null) { fragmentManager .beginTransaction() .hide(fragmentManager.findFragmentByTag(fragmentTagHide)) .commitAllowingStateLoss(); } }