Java Code Examples for com.google.android.material.floatingactionbutton.FloatingActionButton#setVisibility()

The following examples show how to use com.google.android.material.floatingactionbutton.FloatingActionButton#setVisibility() . 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: FabScaleBehavior.java    From NewFastFrame with Apache License 2.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 || dyUnconsumed > 0) && !isAnimatingOut && child.getVisibility() == View.VISIBLE) {//往下滑
        child.setVisibility(View.INVISIBLE);
        AnimatorUtil.scaleHide(child, viewPropertyAnimatorListener);
        if (mOnStateChangedListener != null) {
            mOnStateChangedListener.onChanged(false);
        }
    } else if ((dyConsumed < 0 || dyUnconsumed < 0) && child.getVisibility() != View.VISIBLE) {
        AnimatorUtil.scaleShow(child, null);
        if (mOnStateChangedListener != null) {
            mOnStateChangedListener.onChanged(true);
        }
    }
}
 
Example 2
Source File: FloatingActionButtonAnimBehavior.java    From MultiTypeRecyclerViewAdapter with Apache License 2.0 5 votes vote down vote up
@SuppressLint("RestrictedApi")
private void animateIn(FloatingActionButton button) {
    button.setVisibility(View.VISIBLE);
    ViewCompat.animate(button).translationY(0)
            .setInterpolator(INTERPOLATOR).withLayer().setListener(null)
            .start();
}
 
Example 3
Source File: ScrollAwareFABBehavior.java    From Easy_xkcd 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();
        child.setVisibility(View.VISIBLE);
    }
}
 
Example 4
Source File: ServiceActivity.java    From BonjourBrowser with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_service);
    setSupportActionBar(findViewById(R.id.toolbar));
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    FloatingActionButton fab = findViewById(R.id.fab);
    mServiceName = findViewById(R.id.service_name);
    mRegType = findViewById(R.id.reg_type);
    mDomain = findViewById(R.id.domain);
    mLastTimestamp = findViewById(R.id.last_timestamp);

    ServiceDetailFragment serviceDetailFragment;
    boolean isRegistered = getIntent().getBooleanExtra(REGISTERED, false);

    if (savedInstanceState == null){
        BonjourService service = getIntent().getParcelableExtra(SERVICE);
        serviceDetailFragment = ServiceDetailFragment.newInstance(service);
        getSupportFragmentManager().beginTransaction().replace(R.id.content, serviceDetailFragment).commit();
    }
    else {
        serviceDetailFragment = (ServiceDetailFragment) getSupportFragmentManager().findFragmentById(R.id.content);
    }

    if (isRegistered && fab != null) {
        fab.setVisibility(View.VISIBLE);
        fab.setOnClickListener(serviceDetailFragment);
    }
}
 
Example 5
Source File: DynamicSymbolChangeActivity.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_annotation);

  mapView = findViewById(R.id.mapView);
  mapView.setTag(false);
  mapView.onCreate(savedInstanceState);
  mapView.getMapAsync(mapboxMap -> {
    DynamicSymbolChangeActivity.this.mapboxMap = mapboxMap;

    LatLng target = new LatLng(51.506675, -0.128699);

    mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
      new CameraPosition.Builder()
        .bearing(90)
        .tilt(40)
        .zoom(10)
        .target(target)
        .build()
    ));

    mapboxMap.setStyle(new Style.Builder()
        .fromUri(Style.MAPBOX_STREETS)
        .withImage(ID_ICON_1, generateBitmap(R.drawable.mapbox_ic_place), true)
        .withImage(ID_ICON_2, generateBitmap(R.drawable.mapbox_ic_offline), true)
      , style -> {
        symbolManager = new SymbolManager(mapView, mapboxMap, style);
        symbolManager.setIconAllowOverlap(true);
        symbolManager.setTextAllowOverlap(true);

        // Create Symbol
        SymbolOptions SymbolOptions = new SymbolOptions()
          .withLatLng(LAT_LNG_CHELSEA)
          .withIconImage(ID_ICON_1);

        symbol = symbolManager.create(SymbolOptions);
      });


  });

  FloatingActionButton fab = findViewById(R.id.fabStyles);
  fab.setVisibility(MapView.VISIBLE);
  fab.setOnClickListener(view -> {
    if (mapboxMap != null) {
      updateSymbol();
    }
  });
}
 
Example 6
Source File: ExperimentListFragment.java    From science-journal with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(
    LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  View view = inflater.inflate(R.layout.fragment_experiment_list, container, false);
  final RecyclerView detailList = (RecyclerView) view.findViewById(R.id.details);

  experimentListAdapter = new ExperimentListAdapter(this);

  swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_container);
  swipeLayout.setOnRefreshListener(this);

  // TODO: Adjust the column count based on breakpoint specs when available.
  int column_count = 2;
  GridLayoutManager manager = new GridLayoutManager(getActivity(), column_count);
  manager.setSpanSizeLookup(
      new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
          return experimentListAdapter.getItemViewType(position)
                  == ExperimentListAdapter.VIEW_TYPE_EXPERIMENT
              ? 1
              : column_count;
        }
      });
  detailList.setLayoutManager(manager);
  detailList.setAdapter(experimentListAdapter);

  FloatingActionButton newExperimentButton =
      (FloatingActionButton) view.findViewById(R.id.new_experiment);
  if (claimExperimentsMode) {
    newExperimentButton.setVisibility(View.GONE);
  } else {
    newExperimentButton.setOnClickListener(
        v -> {
          if (getRecorderController().watchRecordingStatus().blockingFirst().isRecording()) {
            // This should never happen, but apparently it does on some Xperia devices?
            // b/117484248
            return;
          }
          getDataController()
              .createExperiment(
                  new LoggingConsumer<Experiment>(TAG, "Create a new experiment") {
                    @Override
                    public void success(final Experiment experiment) {
                      WhistlePunkApplication.getUsageTracker(applicationContext)
                          .trackEvent(
                              TrackerConstants.CATEGORY_EXPERIMENTS,
                              TrackerConstants.ACTION_CREATE,
                              TrackerConstants.LABEL_EXPERIMENT_LIST,
                              0);
                      launchExperimentActivity(
                          v.getContext(),
                          appAccount,
                          experiment.getExperimentId(),
                          false /* claimExperimentsMode */);
                    }
                  });
        });
  }

  return view;
}
 
Example 7
Source File: FABMenu.java    From Jockey with Apache License 2.0 4 votes vote down vote up
private FloatingActionButton buildChild(@DrawableRes int icon,
                                        final OnClickListener onClickListener, String label) {
    FloatingActionButton button = LayoutInflater.from(getContext())
            .inflate(R.layout.mini_fab, (ViewGroup) getParent(), true)
            .findViewWithTag("fab-null");

    button.setTag("fab-" + label);
    button.setImageResource(icon);
    button.setVisibility(GONE);
    button.setOnClickListener(v -> {
        onClickListener.onClick(v);
        hideChildren();
    });

    if (getParent() instanceof CoordinatorLayout) {
        final float padding = getResources().getDimension(R.dimen.fab_margin);
        final float dpScale = getResources().getDisplayMetrics().density;

        CoordinatorLayout.LayoutParams params =
                (CoordinatorLayout.LayoutParams) button.getLayoutParams();
        if (ViewUtils.isRtl(getContext())) {
            params.leftMargin += padding;
        } else {
            params.rightMargin += padding;
        }
        params.bottomMargin = (int) (SIZE_L_DP * dpScale + padding * (2 + children.size())
                + SIZE_S_DP * dpScale * children.size());

        // For some reason, the children are 12dp higher and 18dp further to the left on pre-L
        // devices than on L+ devices. I don't know for sure what causes this (I suspect it's
        // the drop shadow or elevation compatibility code), but this takes care of it.
        //
        // There's probably a better way to fix this, but this was the easiest. If for some
        // reason this changes in an update to one of the support libraries, just remeasure
        // these offsets and update them here.
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            if (ViewUtils.isRtl(getContext())) {
                params.leftMargin -= 12 * dpScale;
            } else {
                params.rightMargin -= 12 * dpScale;
            }
            params.bottomMargin -= 18 * dpScale;
        }

        button.setLayoutParams(params);
    } else {
        Timber.e("Parent must be a CoordinatorLayout to properly set margin");
    }

    // When children aren't visible on screen, remove them from the view hierarchy completely
    // If we don't do this, then the FloatingActionButton Behaviors conflict for some reason
    // and Snackbars won't slide the FAB up which is kind of an important detail.
    //
    // FABMenu.Behavior takes care of some of the left over discrepancies like overlapping FAB's
    //
    // Additionally, the screen is functionally important because it prevents the user
    // from doing something that could generate a Snackbar when the FAB's are visible
    // which can cause the main FAB to be overlapped.
    ((ViewGroup) button.getParent()).removeView(button);
    return button;
}