Java Code Examples for android.support.design.widget.FloatingActionButton#hide()

The following examples show how to use android.support.design.widget.FloatingActionButton#hide() . 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: MainActivity.java    From rosetta with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

    // This floating button switching between Arabic and English Locales manually upon click
    final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    setSupportActionBar(toolbar);

    if (MainApplication.languageSwitcher.getCurrentLocale().getLanguage().equals("ar"))   {
        fab.hide();
    } else {
        fab.show();
    }

    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            MainApplication.languageSwitcher.switchToLaunch(MainActivity.this);
        }
    });
}
 
Example 2
Source File: ScrollAwareFABBehavior.java    From privacy-friendly-passwordgenerator with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onNestedScroll(final CoordinatorLayout coordinatorLayout, final FloatingActionButton child,
                           final View target, final int dxConsumed, final int dyConsumed,
                           final int dxUnconsumed, final int dyUnconsumed) {
    super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);
    if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) {
        // User scrolled down and the FAB is currently visible -> hide the FAB
        child.hide(new FloatingActionButton.OnVisibilityChangedListener() {
            @Override
            public void onHidden(FloatingActionButton fab) {
                super.onHidden(fab);
                fab.setVisibility(View.INVISIBLE);
            }
        });
    } else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) {
        // User scrolled up and the FAB is currently not visible -> show the FAB
        child.show();
    }
}
 
Example 3
Source File: FloatingActionButtonScrollBehavior.java    From FakeWeather with Apache License 2.0 6 votes vote down vote up
@Override
public void onNestedScroll(final CoordinatorLayout coordinatorLayout, final
FloatingActionButton child, final View target, final int dxConsumed, final int dyConsumed,
                           final int dxUnconsumed, final int dyUnconsumed) {
    super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed,
            dxUnconsumed, dyUnconsumed);
    if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) {
        /** design lib 升级到 25.1.0 导致 child.hide() 效果失效,法克哟
         *  http://stackoverflow.com/questions/41761736/android-design-library-25-1-0-causes-floatingactionbutton-behavior-to-stop-worki
         */
        child.hide(new FloatingActionButton.OnVisibilityChangedListener() {
            @Override
            public void onHidden(FloatingActionButton fab) {
                super.onHidden(fab);
                fab.setVisibility(View.INVISIBLE);
            }
        });
    } else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) {
        child.show();
    }
}
 
Example 4
Source File: AnagramsActivity.java    From jterm-cswithandroid with Apache License 2.0 5 votes vote down vote up
public boolean defaultAction(View view) {
    TextView gameStatus = (TextView) findViewById(R.id.gameStatusView);
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    EditText editText = (EditText) findViewById(R.id.editText);
    TextView resultView = (TextView) findViewById(R.id.resultView);
    if (currentWord == null) {
        currentWord = dictionary.pickGoodStarterWord();
        anagrams = dictionary.getAnagramsWithOneMoreLetter(currentWord);
        gameStatus.setText(Html.fromHtml(String.format(START_MESSAGE, currentWord.toUpperCase(), currentWord)));
        fab.setImageResource(android.R.drawable.ic_menu_help);
        fab.hide();
        resultView.setText("");
        editText.setText("");
        editText.setEnabled(true);
        editText.requestFocus();
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
    } else {
        editText.setText(currentWord);
        editText.setEnabled(false);
        fab.setImageResource(android.R.drawable.ic_media_play);
        currentWord = null;
        resultView.append(TextUtils.join("\n", anagrams));
        gameStatus.append(" Hit 'Play' to start again");
    }
    return true;
}
 
Example 5
Source File: MainActivity.java    From v9porn with MIT License 5 votes vote down vote up
private void hideFloatingActionButton(FloatingActionButton fabSearch) {
    ViewGroup.LayoutParams layoutParams = fabSearch.getLayoutParams();
    if (layoutParams instanceof CoordinatorLayout.LayoutParams) {
        CoordinatorLayout.LayoutParams coLayoutParams = (CoordinatorLayout.LayoutParams) layoutParams;
        FloatingActionButton.Behavior behavior = new FloatingActionButton.Behavior();
        coLayoutParams.setBehavior(behavior);
    }
    fabSearch.hide();
}
 
Example 6
Source File: ScrollAwareFABBehavior.java    From Rumble with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onNestedScroll(CoordinatorLayout coordinatorLayout,
                           FloatingActionButton child,
                           View target, int dxConsumed, int dyConsumed,
                           int dxUnconsumed, int dyUnconsumed) {
    super.onNestedScroll(coordinatorLayout, child, target,
            dxConsumed, dyConsumed, dxUnconsumed,dyUnconsumed);

    if ((dyConsumed > 0) && (child.getVisibility() == View.VISIBLE)) {
        child.hide();
    } else if ((dyConsumed < 0) && (child.getVisibility() != View.VISIBLE)) {
        child.show();
    }
}
 
Example 7
Source File: ScrollAwareFABBehavior.java    From MicroReader with MIT License 5 votes vote down vote up
@Override
public void onNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
    super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);
    if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) {
        child.hide();
    } else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) {
        child.show();
    }
}
 
Example 8
Source File: AnagramsActivity.java    From jterm-cswithandroid with Apache License 2.0 5 votes vote down vote up
public boolean defaultAction(View view) {
    TextView gameStatus = (TextView) findViewById(R.id.gameStatusView);
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    EditText editText = (EditText) findViewById(R.id.editText);
    TextView resultView = (TextView) findViewById(R.id.resultView);
    if (currentWord == null) {
        currentWord = dictionary.pickGoodStarterWord();
        anagrams = dictionary.getAnagramsWithOneMoreLetter(currentWord);
        gameStatus.setText(Html.fromHtml(String.format(START_MESSAGE, currentWord.toUpperCase(), currentWord)));
        fab.setImageResource(android.R.drawable.ic_menu_help);
        fab.hide();
        resultView.setText("");
        editText.setText("");
        editText.setEnabled(true);
        editText.requestFocus();
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
    } else {
        editText.setText(currentWord);
        editText.setEnabled(false);
        fab.setImageResource(android.R.drawable.ic_media_play);
        currentWord = null;
        resultView.append(TextUtils.join("\n", anagrams));
        gameStatus.append(" Hit 'Play' to start again");
    }
    return true;
}
 
Example 9
Source File: ScrollAwareFABBehavior.java    From FilePickerLibrary with Apache License 2.0 5 votes vote down vote up
@Override
public void onNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child,
                           View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
    super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed,
            dyUnconsumed);

    if ((dyConsumed > 0) && (child.getVisibility() == View.VISIBLE)) {
        child.hide();
    } else if ((dyConsumed < 0) && (child.getVisibility() != View.VISIBLE)) {
        child.show();
    }
}
 
Example 10
Source File: FloatingActionButtonBehavior.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
@Override public boolean onDependentViewChanged(@NonNull
                                                final CoordinatorLayout parent, @NonNull
                                                final FloatingActionButton child, final View dependency) {
    log(TAG, INFO, "onDependentViewChanged: " + dependency);
    final List<View> list = parent.getDependencies(child);
    ViewGroup.MarginLayoutParams params = ((ViewGroup.MarginLayoutParams) child.getLayoutParams());
    int bottomMargin = (params.bottomMargin + params.rightMargin) - (params.topMargin + params.leftMargin);
    float t = 0;
    float t2 = 0;
    float t3 = 0;
    boolean result = false;
    for (View dep : list) {
        if (Snackbar.SnackbarLayout.class.isInstance(dep)) {
            t += dep.getTranslationY() - dep.getHeight();
            result = true;
        } else if (BottomNavigation.class.isInstance(dep)) {
            BottomNavigation navigation = (BottomNavigation) dep;
            t2 = navigation.getTranslationY() - navigation.getHeight() + bottomMargin;
            t += t2;
            result = true;

            if (navigationBarHeight > 0) {
                if (!navigation.isExpanded()) {
                    child.hide();
                } else {
                    child.show();
                }
            }
        }
    }

    if (navigationBarHeight > 0 && t2 < 0) {
        t = Math.min(t2, t + navigationBarHeight);
    }

    child.setTranslationY(t);
    return result;
}
 
Example 11
Source File: ScrollAwareFABBehavior.java    From react-native-bottom-sheet-behavior with MIT License 5 votes vote down vote up
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, FloatingActionButton child, View dependency) {
    /**
     * Because we are not moving it, we always return false in this method.
     */

    if (offset == 0)
        setOffsetValue(parent);

    if (mBottomSheetBehaviorRef == null)
        getBottomSheetBehavior(parent);

    int DyFix = getDyBetweenChildAndDependency(child, dependency);

    if ((child.getY() + DyFix) < offset)
        child.hide();
    else if ((child.getY() + DyFix) >= offset) {

        /**
         * We are calculating every time point in Y where BottomSheet get {@link BottomSheetBehaviorGoogleMapsLike#STATE_COLLAPSED}.
         * If PeekHeight change dynamically we can reflect the behavior asap.
         */
        if (mBottomSheetBehaviorRef == null || mBottomSheetBehaviorRef.get() == null)
            getBottomSheetBehavior(parent);
        int collapsedY = dependency.getHeight() - mBottomSheetBehaviorRef.get().getPeekHeight();

        if ((child.getY() + DyFix) > collapsedY)
            child.hide();
        else
            child.show();
    }

    return false;
}
 
Example 12
Source File: FragmentAdapter.java    From SteamGifts with MIT License 5 votes vote down vote up
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    FloatingActionButton scrollToTopButton = (FloatingActionButton) activity.findViewById(R.id.scroll_to_top_button);
    if (scrollToTopButton != null && positionOffsetPixels != 0) {
        scrollToTopButton.hide();
        scrollToTopButton.setTag(null);
    }
}
 
Example 13
Source File: ScrollAwareFABBehavior.java    From android-wallet-app with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull FloatingActionButton child, @NonNull View target, int dxConsumed, int dyConsunmed, int dxUnconsumed, int dyUnconsumed, int type) {
    if (dyConsunmed > 0 && child.getVisibility() == View.VISIBLE) {
        child.hide();
    } else if (dyConsunmed < 0 && child.getVisibility() != View.VISIBLE) {
        child.show();
    }
}
 
Example 14
Source File: FloatingActionButtonBehavior.java    From AndroidPlusJava with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull FloatingActionButton child, @NonNull View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type) {
    if (dyConsumed > 0) {
        child.hide(new FloatingActionButton.OnVisibilityChangedListener() {
            @Override
            public void onHidden(FloatingActionButton fab) {
                fab.setVisibility(View.INVISIBLE);
            }
        });
    } else {
        child.show();
    }
}
 
Example 15
Source File: ScrollHideBehavior.java    From octoandroid with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
    super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);
    child.hide();
}
 
Example 16
Source File: ScrollAwareFABBehavior.java    From SteamGifts with MIT License 4 votes vote down vote up
@Override
public void onNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
    super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);

    if (child.getTag() == null) {
        return;
    }

    // try to get the current page, if there's any.
    View view = coordinatorLayout;
    ViewPager viewPager = (ViewPager) coordinatorLayout.findViewById(R.id.viewPager);
    if (viewPager != null && viewPager.getAdapter() instanceof FragmentAdapter) {
        int currentPage = viewPager.getCurrentItem();
        FragmentAdapter pagerAdapter = (FragmentAdapter) viewPager.getAdapter();

        Fragment currentItem = pagerAdapter.getItem(currentPage);

        view = currentItem.getView();
    }

    if (view == null) {
        // We do not have a view we can immediately find.
        child.hide();
        return;
    }

    // Hide if we're over the first item
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list);
    if (recyclerView != null && recyclerView.getLayoutManager() instanceof LinearLayoutManager) {
        LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
        if (layoutManager.findFirstVisibleItemPosition() == 0) {
            child.hide();
        } else if (dyConsumed > 1 && child.getVisibility() == View.VISIBLE)
            child.hide();
        else if (dyConsumed < 1 && child.getVisibility() != View.VISIBLE)
            child.show();
    } else {
        // no recyclerview to attach to?
        child.hide();
    }
}
 
Example 17
Source File: FragmentNavigationActivity.java    From graphhopper-navigation-android with MIT License 4 votes vote down vote up
@OnClick(R.id.restart_navigation_fab)
public void onClick(FloatingActionButton restartNavigationFab) {
  replaceFragment(new NavigationFragment());
  restartNavigationFab.hide();
}
 
Example 18
Source File: MainActivity.java    From explorer with Apache License 2.0 4 votes vote down vote up
private void initFloatingActionButton() {

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.floating_action_button);

        if (fab == null) return;

        fab.setOnClickListener(v -> actionCreate());

        if (name != null || type != null) {

            ViewGroup.LayoutParams layoutParams = fab.getLayoutParams();

            ((CoordinatorLayout.LayoutParams) layoutParams).setAnchorId(View.NO_ID);

            fab.setLayoutParams(layoutParams);

            fab.hide();
        }
    }
 
Example 19
Source File: Permission.java    From soundcom with Apache License 2.0 4 votes vote down vote up
public void initTransmit() {
        final Context context = getApplicationContext();

        CharSequence text = "Transmitter Mode Activated";
        int duration = Toast.LENGTH_SHORT;

        long free = Runtime.getRuntime().freeMemory();
//        generate(context);

        Toast toast = Toast.makeText(context, text, duration);
        toast.show();

        setContentView(R.layout.activity_transmitter);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
        navigationView.setCheckedItem(R.id.transmit);


        gen = (Button) findViewById(R.id.generate);
        gen.setOnClickListener(this);
        mEdit = (EditText) findViewById(R.id.transmitString);


        fab_trans = (FloatingActionButton) findViewById(R.id.fab);
        fab_trans.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Transmitting Modulated Waveform", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();

                mediaplayer = new MediaPlayer();


                String root = Environment.getExternalStorageDirectory().toString();
                File dir = new File(root, "RedTooth");
                if (!dir.exists()) {
                    dir.mkdir();
                }

                try {
                    mediaplayer.setDataSource(dir + File.separator + "FSK.wav");
                    mediaplayer.prepare();
                    mediaplayer.start();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        fab_trans.hide();


    }
 
Example 20
Source File: MainActivity.java    From soundcom with Apache License 2.0 4 votes vote down vote up
public void initTransmit() {
        final Context context = getApplicationContext();

        CharSequence text = "Transmitter Mode Activated";
        int duration = Toast.LENGTH_SHORT;

        long free = Runtime.getRuntime().freeMemory();
//        generate(context);

        Toast toast = Toast.makeText(context, text, duration);
        toast.show();

        setContentView(R.layout.activity_transmitter);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
        navigationView.setCheckedItem(R.id.transmit);


        gen = (Button) findViewById(R.id.generate);
        mEdit = (EditText) findViewById(R.id.transmitString);
        gen.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                clickHelper(context,mEdit,v);
            }

        });


        fab_trans = (FloatingActionButton) findViewById(R.id.fab);
        fab_trans.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {  //playing the wav file
                Snackbar.make(view, "Transmitting Modulated Waveform", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();

                mediaplayer = new MediaPlayer();

                String root = Environment.getExternalStorageDirectory().toString();
                File dir = new File(root, "Soundcom");
                if (!dir.exists()) {
                    dir.mkdir();
                }

                try {
                    mediaplayer.setDataSource(dir + File.separator + "FSK.wav");
                    mediaplayer.prepare();
                    mediaplayer.start();
                    MemberData data = new MemberData(a, getRandomColor());
                    boolean belongsToCurrentUser=true;
                    final Message message = new Message(src, data, belongsToCurrentUser);
                    printmessage(message);  //add transmitted message to chat

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        fab_trans.hide();
    }