com.google.android.material.floatingactionbutton.FloatingActionButton Java Examples

The following examples show how to use com.google.android.material.floatingactionbutton.FloatingActionButton. 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: BottomNavBarFabBehaviour.java    From BottomNavigation with Apache License 2.0 6 votes vote down vote up
private float[] getFabTranslationYForBottomNavigationBar(CoordinatorLayout parent,
                                                         FloatingActionButton fab) {
    float minOffset = 0;
    float viewHeight = 0;
    final List<View> dependencies = parent.getDependencies(fab);
    for (int i = 0, z = dependencies.size(); i < z; i++) {
        final View view = dependencies.get(i);
        if (view instanceof BottomNavigationBar) {
            viewHeight = view.getHeight();
            minOffset = Math.min(minOffset,
                    view.getTranslationY() - viewHeight);
        }
    }

    return new float[]{minOffset, viewHeight};
}
 
Example #2
Source File: ComicFragment.java    From Easy_xkcd with Apache License 2.0 6 votes vote down vote up
@Override
public void onPrepareOptionsMenu(Menu menu) {
    //Update the favorites icon
    MenuItem fav = menu.findItem(R.id.action_favorite);
    if (databaseManager.isFavorite(lastComicNumber)) {
        fav.setIcon(R.drawable.ic_favorite_on_24dp);
        fav.setTitle(R.string.action_favorite_remove);
    } else {
        fav.setIcon(R.drawable.ic_favorite_off_24dp);
        fav.setTitle(R.string.action_favorite);
    }
    //If the FAB is visible, hide the random comic menu item
    if (getActivity() != null) {
        FloatingActionButton fab = getMainActivity().getFab();
        menu.findItem(R.id.action_random).setVisible(fab != null && fab.getVisibility() == View.GONE);
    }
    menu.findItem(R.id.action_alt).setVisible(prefHelper.showAltTip());
    menu.findItem(R.id.action_browser).setVisible(true);
}
 
Example #3
Source File: CircleMenuView.java    From circle-menu-android with MIT License 6 votes vote down vote up
private void initButtons(@NonNull Context context, @NonNull List<Integer> icons, @NonNull List<Integer> colors) {
    final int buttonsCount = Math.min(icons.size(), colors.size());
    for (int i = 0; i < buttonsCount; i++) {
        final FloatingActionButton button = new FloatingActionButton(context);
        button.setImageResource(icons.get(i));
        button.setBackgroundTintList(ColorStateList.valueOf(colors.get(i)));
        button.setClickable(true);
        button.setOnClickListener(new OnButtonClickListener());
        button.setOnLongClickListener(new OnButtonLongClickListener());
        button.setScaleX(0);
        button.setScaleY(0);
        button.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

        addView(button);
        mButtons.add(button);
    }
}
 
Example #4
Source File: FloatingActionButtonActions.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
public static ViewAction setCompatElevation(final float size) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(FloatingActionButton.class);
    }

    @Override
    public String getDescription() {
      return "Sets FloatingActionButton elevation";
    }

    @Override
    public void perform(UiController uiController, View view) {
      final FloatingActionButton fab = (FloatingActionButton) view;
      fab.setCompatElevation(size);
    }
  };
}
 
Example #5
Source File: FlagTwoActivity.java    From InjuredAndroid with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_flag_two);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (click == 0) {
                Snackbar.make(view, "Key words Activity and exported.", Snackbar.LENGTH_LONG)
                        .setAction("Action",null).show();
                click = click + 1;
            } else if (click == 1) {
                Snackbar.make(view, "Exported Activities can be accessed with adb or Drozer.", Snackbar.LENGTH_LONG)
                        .setAction("Action",null).show();
                click = 0;
            }
        }
    });
}
 
Example #6
Source File: ChartActionBarView.java    From openScale with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    FloatingActionButton actionButton = (FloatingActionButton) v;

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());

    String key = String.valueOf(actionButton.getTag());
    MeasurementViewSettings settings = new MeasurementViewSettings(prefs, key);
    if (isInGraphKey) {
        prefs.edit().putBoolean(settings.getInGraphKey(), !settings.isInGraph()).apply();
    } else {
        prefs.edit().putBoolean(settings.getInOverviewGraphKey(), !settings.isInOverviewGraph()).apply();
    }

    refreshFloatingActionsButtons();

    if (onActionClickListener != null) {
        onActionClickListener.onClick(v);
    }
}
 
Example #7
Source File: CaptureInfoActivity.java    From NetworkCaptureSelf with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_capture_slide);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    setTitle("APP内抓包工具");


    FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            CacheUtils.getInstance().cleanCache();
            GetCaptureDataUtils.getSlidData(CaptureInfoActivity.this);
            contentAdapter.clear();
            Snackbar.make(view, "清除抓包数据成功", Snackbar.LENGTH_SHORT)
                    .setAction("Action", null).show();
        }
    });

    initView();
}
 
Example #8
Source File: MainActivity.java    From MycroftCore-Android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    loadExtension(this, "wikipedia", "wikipedia");
}
 
Example #9
Source File: MainActivity.java    From Android-Dev-Box with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });
}
 
Example #10
Source File: BubbleActivity.java    From journaldev with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bubble);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);


    textView = findViewById(R.id.textView);

    FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });


}
 
Example #11
Source File: MainActivity.java    From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(MainActivity.this, OrderActivity.class);
            intent.putExtra(EXTRA_MESSAGE, mOrderMessage);
            startActivity(intent);
        }
    });

    PreferenceManager.setDefaultValues(this, R.xml.sync_preferences, false);
    PreferenceManager.setDefaultValues(this, R.xml.general_preferences, false);
    PreferenceManager.setDefaultValues(this, R.xml.notification_preferences, false);
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    String marketPref = sharedPreferences.getString("sync_frequency", "-1");
    String deliveryMethod = sharedPreferences.getString("delivery_list", "Same day messenger service");
    displayToast("Market is " + marketPref + " and delivery method is " + deliveryMethod);
}
 
Example #12
Source File: FloatingActionButtonActions.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a {@link ViewAction} that requests will make the visual representation of the FAB fill
 * the {@link View}. It will remove corners, shadow padding, and stop ensuring min touch target
 * size. This should only be used to help with checking color contrast heuristics.
 */
public static ViewAction fillView() {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(FloatingActionButton.class);
    }

    @Override
    public String getDescription() {
      return "removing corner radii from FAB";
    }

    @Override
    public void perform(UiController uiController, View view) {
      FloatingActionButton fab = (FloatingActionButton) view;
      fab.setShapeAppearanceModel(new ShapeAppearanceModel());
      fab.setShadowPaddingEnabled(false);
      fab.setEnsureMinTouchTargetSize(false);
    }
  };
}
 
Example #13
Source File: MainActivity.java    From centering-recycler-view with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mRecyclerView = findViewById(R.id.recycler_view);
    mRecyclerView.setAdapter(new DemoAdapter(R.layout.linear_vertical));
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    final FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            int position = mRand.nextInt(DemoAdapter.ITEM_COUNT);
            mRecyclerView.center(position);
            ActionBar ab = getSupportActionBar();
            if (ab != null) {
                ab.setSubtitle(getString(R.string.subtitle, position));
            }
        }
    });
}
 
Example #14
Source File: AppBarWithAnchoredFabMarginsTest.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Test
public void testFabTopMargin() throws Throwable {
  configureContent(
      R.layout.design_appbar_anchored_fab_margin_top,
      R.string.design_appbar_anchored_fab_margin_top);

  final FloatingActionButton fab = mCoordinatorLayout.findViewById(R.id.fab);
  final CoordinatorLayout.LayoutParams fabLp =
      (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
  assertEquals(mAppBar.getId(), fabLp.getAnchorId());

  final int[] appbarOnScreenXY = new int[2];
  final int[] fabOnScreenXY = new int[2];
  mAppBar.getLocationOnScreen(appbarOnScreenXY);
  fab.getLocationOnScreen(fabOnScreenXY);

  // FAB is horizontally centered in the coordinate system of its anchor (app bar).
  assertEquals(
      appbarOnScreenXY[0] + mAppBar.getWidth() / 2, fabOnScreenXY[0] + fab.getWidth() / 2, 1);
  // Top margin is in the coordinate space of the parent (CoordinatorLayout) and not
  // the anchor. Since our FAB is far enough from the bottom edge of CoordinatorLayout,
  // we are expecting the vertical center of the FAB to be aligned with the bottom edge
  // of its anchor (app bar).
  assertEquals(
      appbarOnScreenXY[1] + mAppBar.getHeight(), fabOnScreenXY[1] + fab.getHeight() / 2, 1);
}
 
Example #15
Source File: ViewPagerNestedActivity.java    From AndroidAnimationExercise with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view_pager_nested);
    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);


    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

}
 
Example #16
Source File: FileSheet.java    From Aria2App with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected boolean onCustomizeAction(@NonNull FloatingActionButton action, @NonNull SetupPayload payload) {
    try {
        MultiProfile profile = ProfilesManager.get(requireContext()).getCurrent();
        if (payload.download.update().isMetadata() || profile.getProfile(getContext()).directDownload == null) {
            return false;
        } else {
            action.setImageResource(R.drawable.baseline_download_24);
            action.setSupportImageTintList(ColorStateList.valueOf(Color.WHITE));
            CommonUtils.setBackgroundColor(action, payload.download.update().getColorVariant());
            action.setOnClickListener(v -> payload.listener.onDownloadFile(profile, payload.file, false));
            action.setOnLongClickListener(v -> {
                payload.listener.onDownloadFile(profile, payload.file, true);
                return true;
            });
            return true;
        }
    } catch (ProfilesManager.NoCurrentProfileException ex) {
        Log.e(TAG, "No profile found.", ex);
        return false;
    }
}
 
Example #17
Source File: PrefHelper.java    From Easy_xkcd with Apache License 2.0 6 votes vote down vote up
public void showFeatureSnackbar(final Activity activity, FloatingActionButton fab) {
    if (!sharedPrefs.getBoolean(CUSTOM_THEMES_SNACKBAR, false)) {
        View.OnClickListener oc = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(activity, NestedSettingsActivity.class);
                intent.putExtra("key", "appearance");
                activity.startActivityForResult(intent, 1);
            }
        };
        SharedPreferences.Editor editor = sharedPrefs.edit();
        editor.putBoolean(CUSTOM_THEMES_SNACKBAR, true);
        editor.apply();
        Snackbar.make(fab, R.string.snackbar_feature, Snackbar.LENGTH_LONG)
                .setAction(R.string.snackbar_feature_oc, oc)
                .show();
    }
}
 
Example #18
Source File: AppBarBoundFabBehavior.java    From appbarsyncedfab with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, FloatingActionButton fab, View dependency) {
    //noinspection SimplifiableIfStatement
    if (dependency instanceof AppBarLayout) {
        // if the dependency is an AppBarLayout, do not allow super to react on that
        // we don't want that behavior
        return true;
    } else if (dependency instanceof Snackbar.SnackbarLayout) {
        updateFabTranslationForSnackbar(parent, fab, dependency);
        return true;
    }
    return super.onDependentViewChanged(parent, fab, dependency);
}
 
Example #19
Source File: AppBarBoundFabBehavior.java    From appbarsyncedfab with Apache License 2.0 5 votes vote down vote up
/**
 * returns visible height of snackbar, if snackbar is overlapping fab
 * 0 otherwise
 */
private float getVisibleHeightOfOverlappingSnackbar(CoordinatorLayout parent,
                                                    FloatingActionButton fab) {
    float minOffset = 0;
    final List<View> dependencies = parent.getDependencies(fab);
    for (int i = 0, z = dependencies.size(); i < z; i++) {
        final View view = dependencies.get(i);
        if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(fab, view)) {
            minOffset = Math.min(minOffset, view.getTranslationY() - view.getHeight());
        }
    }

    return minOffset;
}
 
Example #20
Source File: MainActivity.java    From UploadToJitpack with Apache License 2.0 5 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);
  setSupportActionBar(toolbar);

  FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
  fab.setOnClickListener(new View.OnClickListener() {
    @Override public void onClick(View view) {
      Snackbar.make(view, AwesomeLib.getInstance().makeAwesome("Nishant"), Snackbar.LENGTH_LONG)
          .setAction("Action", null)
          .show();
    }
  });
}
 
Example #21
Source File: CrashReport.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    FloatingActionButton floatingButton = mFragmentHolder.enableActionButton();
    floatingButton.setImageDrawable(getContext().getDrawable(R.drawable.ic_send));
    floatingButton.setOnClickListener(v -> {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
        File file = MapTrek.getApplication().getExceptionLog();
        intent.putExtra(Intent.EXTRA_STREAM, ExportProvider.getUriForFile(getContext(), file));
        intent.setType("vnd.android.cursor.dir/email");
        intent.putExtra(Intent.EXTRA_SUBJECT, "MapTrek crash report");
        StringBuilder text = new StringBuilder();
        text.append("Device : ").append(Build.DEVICE);
        text.append("\nBrand : ").append(Build.BRAND);
        text.append("\nModel : ").append(Build.MODEL);
        text.append("\nProduct : ").append(Build.PRODUCT);
        text.append("\nLocale : ").append(Locale.getDefault().toString());
        text.append("\nBuild : ").append(Build.DISPLAY);
        text.append("\nVersion : ").append(Build.VERSION.RELEASE);
        try {
            PackageInfo info = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
            if (info != null) {
                text.append("\nApk Version : ").append(info.versionCode).append(" ").append(info.versionName);
            }
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        intent.putExtra(Intent.EXTRA_TEXT, text.toString());
        startActivity(Intent.createChooser(intent, getString(R.string.send_crash_report)));
        mFragmentHolder.disableActionButton();
        mFragmentHolder.popCurrent();
    });
}
 
Example #22
Source File: FABHideOnScrollBehavior.java    From hipda with GNU General Public License v2.0 5 votes vote down vote up
public static void hideFab(FloatingActionButton child) {
    child.hide(new FloatingActionButton.OnVisibilityChangedListener() {
        @Override
        public void onHidden(FloatingActionButton fab) {
            super.onHidden(fab);
            fab.setVisibility(View.INVISIBLE);
        }
    });
}
 
Example #23
Source File: Advance3DDrawer1Activity.java    From Drawer-Behavior with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_advance_3d_1);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

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

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

    drawer.setViewScale(GravityCompat.START, 0.96f);
    drawer.setRadius(GravityCompat.START, 20);
    drawer.setViewElevation(GravityCompat.START, 8);
    drawer.setViewRotation(GravityCompat.START, 15);



}
 
Example #24
Source File: FabScrollBehaviour.java    From leafpicrevived 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.animate().translationY(child.getHeight() * 4).setInterpolator(new AccelerateInterpolator(2)).start();
    else
        child.animate().translationY(/*-Measure.getNavigationBarSize(coordinatorLayout
        .getContext()).y*/0).setInterpolator(new DecelerateInterpolator(2)).start();
}
 
Example #25
Source File: AdvanceDrawer3Activity.java    From Drawer-Behavior with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_advance3);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

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

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

    drawer.setViewScale(Gravity.START, 0.9f);
    drawer.setViewElevation(Gravity.START, 20);

    drawer.useCustomBehavior(Gravity.END);

}
 
Example #26
Source File: AppBarWithDodgingTest.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testLeftDodge() throws Throwable {
  configureContent(R.layout.design_appbar_dodge_left, R.string.design_appbar_dodge_left);

  final FloatingActionButton fab = mCoordinatorLayout.findViewById(R.id.fab);
  final FloatingActionButton fab2 = mCoordinatorLayout.findViewById(R.id.fab2);

  final int[] fabOnScreenXY = new int[2];
  final int[] fab2OnScreenXY = new int[2];
  fab.getLocationOnScreen(fabOnScreenXY);
  fab2.getLocationOnScreen(fab2OnScreenXY);

  final Rect fabRect = new Rect();
  final Rect fab2Rect = new Rect();
  fab.getContentRect(fabRect);
  fab2.getContentRect(fab2Rect);

  // Our second FAB is configured to "dodge" the first one - to be displayed to the
  // right of it
  int firstRight = fabOnScreenXY[0] + fabRect.right;
  int secondLeft = fab2OnScreenXY[0] + fab2Rect.left;
  assertTrue(
      "Second button left edge at "
          + secondLeft
          + " should be dodging the first button right edge at "
          + firstRight,
      secondLeft >= firstRight);
}
 
Example #27
Source File: ProteusActivity.java    From proteus with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  setContentView(R.layout.activity_proteus);

  // set the toolbar
  Toolbar toolbar = findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);

  // setBoolean refresh button click
  FloatingActionButton fab = findViewById(R.id.fab);
  fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
      alert();
    }
  });

  container = findViewById(R.id.content_main);

  DemoApplication application = (DemoApplication) getApplication();
  proteusManager = application.getProteusManager();

  ProteusContext context = proteusManager.getProteus().createContextBuilder(this)
    .setLayoutManager(layoutManager)
    .setCallback(callback)
    .setImageLoader(loader)
    .setStyleManager(styleManager)
    .build();

  layoutInflater = context.getInflater();
}
 
Example #28
Source File: BottomNavBarFabBehaviour.java    From BottomNavigation with Apache License 2.0 5 votes vote down vote up
private float getFabTranslationYForSnackBar(CoordinatorLayout parent,
                                            FloatingActionButton fab) {
    float minOffset = 0;
    final List<View> dependencies = parent.getDependencies(fab);
    for (int i = 0, z = dependencies.size(); i < z; i++) {
        final View view = dependencies.get(i);
        if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(fab, view)) {
            minOffset = Math.min(minOffset,
                    view.getTranslationY() - view.getHeight());
        }
    }

    return minOffset;
}
 
Example #29
Source File: ManageWalletsActivity.java    From zap-android with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_manage_wallets);

    mRecyclerView = findViewById(R.id.historyList);
    mEmptyListText = findViewById(R.id.listEmpty);

    mWalletItems = new ArrayList<>();

    // use a linear layout manager
    mLayoutManager = new LinearLayoutManager(ManageWalletsActivity.this);
    mRecyclerView.setLayoutManager(mLayoutManager);

    // create and set adapter
    mAdapter = new WalletItemAdapter(mWalletItems);
    mRecyclerView.setAdapter(mAdapter);


    FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Add a new wallet
            Intent intent = new Intent(ManageWalletsActivity.this, SetupActivity.class);
            startActivity(intent);
        }
    });
}
 
Example #30
Source File: FavoritesScene.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Override
@Implemented(FabLayout.OnClickFabListener.class)
public void onClickPrimaryFab(FabLayout view, FloatingActionButton fab) {
    if (mRecyclerView != null && mFabLayout != null) {
        if (mRecyclerView.isInCustomChoice()) {
            mRecyclerView.outOfCustomChoiceMode();
        } else {
            mFabLayout.toggle();
        }
    }
}