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

The following examples show how to use com.google.android.material.floatingactionbutton.FloatingActionButton#setImageResource() . 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: 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 2
Source File: BookFloatingActionMenu.java    From HaoReader with GNU General Public License v3.0 6 votes vote down vote up
@SuppressLint("ClickableViewAccessibility")
private void initFloatingActionMenu() {
    for (int i = 0; i <= getChildCount() - 2; i++) {
        ViewGroup childGroup = (ViewGroup) getChildAt(i);
        final int index = Integer.parseInt(String.valueOf(childGroup.getTag()));
        childGroup.setVisibility(INVISIBLE);
        View labelView = childGroup.getChildAt(0);
        labelView.setVisibility(INVISIBLE);
        FloatingActionButton btnView = (FloatingActionButton) childGroup.getChildAt(1);
        btnView.setTag(btnView.getDrawable());
        if (mLastIndex == index) {
            btnView.setImageResource(R.drawable.ic_check_black_24dp);
        }
        labelView.setOnClickListener(v -> btnView.callOnClick());
        btnView.setOnClickListener(v -> {
            setSelection(index);
            collapse();
            if (mMenuClickListener != null) {
                mMenuClickListener.onMenuClick(index, v);
            }
        });
        btnView.post(btnView::hide);
    }
}
 
Example 3
Source File: IntroActivity.java    From lrkFM with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_intro);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    final boolean permissionGranted = ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;

    FloatingActionButton fab = findViewById(R.id.fab);
    if (permissionGranted) {
        fab.setImageResource(R.drawable.ic_chevron_right_white_24dp);
    }
    fab.setOnClickListener(view -> {
        if (!permissionGranted && c <= 0) {
            FileActivity.verifyStoragePermissions(IntroActivity.this);
            fab.setImageResource(R.drawable.ic_chevron_right_white_24dp);
            c++;
        } else {
            launchMainAndFinish(savedInstanceState);
        }
    });
}
 
Example 4
Source File: SatelliteMenuView.java    From CrazyDaily with Apache License 2.0 6 votes vote down vote up
public void setImgRes(ImgResEntity entity) {
    final Context context = getContext();
    final int dp_6 = dp2px(context, 6);
    final int dp_3 = dp2px(context, 3);
    FloatingActionButton fab = new FloatingActionButton(context);
    fab.setPadding(dp_6, dp_6, dp_6, dp_6);
    fab.setElevation(dp_3);
    fab.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    fab.setSize(FloatingActionButton.SIZE_MINI);
    fab.setBackgroundTintList(ColorStateList.valueOf(entity.color));
    fab.setImageResource(entity.res);
    fab.setUseCompatPadding(true);
    final int size = (int) (SIZE * BUTTON_RATIO);
    LayoutParams params = new LayoutParams(size, size);
    params.gravity = Gravity.END | Gravity.BOTTOM;
    addView(fab, params);
    mButtonView = fab;
    mButtonView.setOnClickListener(v -> {
        if (isOpen) {
            close();
        } else {
            show();
        }
    });
}
 
Example 5
Source File: DirectorySheet.java    From Aria2App with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected boolean onCustomizeAction(@NonNull FloatingActionButton action, @NonNull final SetupPayload payload) {
    try {
        final 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);
            CommonUtils.setBackgroundColor(action, payload.download.update().getColorVariant());
            action.setSupportImageTintList(ColorStateList.valueOf(Color.WHITE));
            action.setOnClickListener(v -> payload.listener.onDownloadDirectory(profile, currentDir));
            return true;
        }
    } catch (ProfilesManager.NoCurrentProfileException ex) {
        Log.e(TAG, "No profile found.", ex);
        return false;
    }
}
 
Example 6
Source File: WelcomeFragment.java    From SecondScreen with Apache License 2.0 6 votes vote down vote up
@Override
public void onStart() {
    super.onStart();

    // Change window title
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        getActivity().setTitle(getResources().getString(R.string.app_name));
    else
        getActivity().setTitle(" " + getResources().getString(R.string.app_name));

    // Don't show the Up button in the action bar, and disable the button
    ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
    ((AppCompatActivity) getActivity()).getSupportActionBar().setHomeButtonEnabled(false);

    // Floating action button
    FloatingActionButton floatingActionButton = getActivity().findViewById(R.id.button_floating_action_welcome);
    floatingActionButton.setImageResource(R.drawable.ic_action_new);
    floatingActionButton.setOnClickListener(v -> {
        DialogFragment newProfileFragment = new NewProfileDialogFragment();
        newProfileFragment.show(getFragmentManager(), "new");
    });
}
 
Example 7
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 8
Source File: ProfileListFragment.java    From SecondScreen with Apache License 2.0 6 votes vote down vote up
@Override
public void onStart() {
    super.onStart();

    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(receiver, filter);

    // Floating action button
    FloatingActionButton floatingActionButton = getActivity().findViewById(R.id.button_floating_action);
    floatingActionButton.setImageResource(R.drawable.ic_action_new);
    if(getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-large"))
        floatingActionButton.hide();

    if(getId() == R.id.profileViewEdit) {
        floatingActionButton.show();
        floatingActionButton.setOnClickListener(v -> {
            DialogFragment newProfileFragment = new NewProfileDialogFragment();
            newProfileFragment.show(getFragmentManager(), "new");
        });
    }
}
 
Example 9
Source File: FragmentStaggeredLayout.java    From FlexibleAdapter with Apache License 2.0 6 votes vote down vote up
private int addItem(StaggeredItemStatus status, StaggeredHeaderItem headerItem) {
    StaggeredItem staggeredItem = DatabaseService.newStaggeredItem(
            DatabaseService.getInstance().getMaxStaggeredId(), headerItem);
    staggeredItem.setStatus(status);//!!!

    // The section object is known
    mAdapter.addItemToSection(staggeredItem, staggeredItem.getHeader(),
            new DatabaseService.ItemComparatorByGroup());
    // Add Item to the Database as well for next refresh
    DatabaseService.getInstance().addItem(staggeredItem, new DatabaseService.ItemComparatorById());

    // Change fab action (MOVE ITEM)
    if (mAdapter.getItemCountOfTypes(R.layout.recycler_staggered_item) >= 15) {
        FloatingActionButton fab = getActivity().findViewById(R.id.fab);
        fab.setImageResource(R.drawable.ic_sort_white_24dp);
    }

    // Retrieve the final position due to a possible hidden header became now visible!
    int scrollTo = mAdapter.getGlobalPositionOf(staggeredItem);
    Log.d(TAG, "Creating New Item " + staggeredItem + " at position " + scrollTo);
    return scrollTo;
}
 
Example 10
Source File: FragmentStaggeredLayout.java    From FlexibleAdapter with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_reset) {
        DatabaseService.getInstance().resetItems();
        mAdapter.updateDataSet(DatabaseService.getInstance().getDatabaseList(), true);
    } else if (id == R.id.action_delete) {
        DatabaseService.getInstance().removeAll();
        mAdapter.updateDataSet(null, true);
        // This is necessary if we call updateDataSet() and not removeItems
        DatabaseService.getInstance().resetHeaders();
        // Change fab action (ADD NEW ITEM UNTIL 15)
        FloatingActionButton fab = getActivity().findViewById(R.id.fab);
        fab.setImageResource(R.drawable.fab_add);
    }
    return super.onOptionsItemSelected(item);
}
 
Example 11
Source File: AppUtils.java    From materialistic with Apache License 2.0 6 votes vote down vote up
public static void toggleFabAction(FloatingActionButton fab, WebItem item, boolean commentMode) {
    Context context = fab.getContext();
    fab.setImageResource(commentMode ? R.drawable.ic_reply_white_24dp : R.drawable.ic_zoom_out_map_white_24dp);
    fab.setOnClickListener(v -> {
        if (commentMode) {
            context.startActivity(new Intent(context, ComposeActivity.class)
                    .putExtra(ComposeActivity.EXTRA_PARENT_ID, item.getId())
                    .putExtra(ComposeActivity.EXTRA_PARENT_TEXT,
                            item instanceof Item ? ((Item) item).getText() : null));
        } else {
            LocalBroadcastManager.getInstance(context)
                    .sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN)
                            .putExtra(WebFragment.EXTRA_FULLSCREEN, true));
        }
    });
}
 
Example 12
Source File: FloatingActionButtonActions.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
public static ViewAction setImageResource(@DrawableRes final int resId) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(FloatingActionButton.class);
    }

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

    @Override
    public void perform(UiController uiController, View view) {
      final FloatingActionButton fab = (FloatingActionButton) view;
      fab.setImageResource(resId);
    }
  };
}
 
Example 13
Source File: NoteListFragment.java    From Notepad with Apache License 2.0 5 votes vote down vote up
@Override
public void onStart() {
    super.onStart();

    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(receiver, filter);

    // Floating action button
    FloatingActionButton floatingActionButton = getActivity().findViewById(R.id.button_floating_action);
    floatingActionButton.setImageResource(R.drawable.ic_action_new);
    if(getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-large"))
        floatingActionButton.hide();

    SharedPreferences prefMain = getActivity().getPreferences(Context.MODE_PRIVATE);

    if(getId() == R.id.noteViewEdit && prefMain.getLong("draft-name", 0) == 0) {
        floatingActionButton.show();
        floatingActionButton.setOnClickListener(v -> {
            ScrollPositions.getInstance().setPosition(listView.getFirstVisiblePosition());
            listener.getCabArray().clear();

            Bundle bundle = new Bundle();
            bundle.putString("filename", "new");

            Fragment fragment = new NoteEditFragment();
            fragment.setArguments(bundle);

            // Add NoteEditFragment
            getFragmentManager()
                .beginTransaction()
                .replace(R.id.noteViewEdit, fragment, "NoteEditFragment")
                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE)
                .commit();
        });
    }
}
 
Example 14
Source File: MedicineFragment.java    From Medicine-Time- with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    FloatingActionButton fab = Objects.requireNonNull(getActivity()).findViewById(R.id.fab_add_task);
    fab.setImageResource(R.drawable.ic_add);
    fab.setOnClickListener(v -> presenter.addNewMedicine());
}
 
Example 15
Source File: AddMedicineFragment.java    From Medicine-Time- with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    FloatingActionButton fab = Objects.requireNonNull(getActivity()).findViewById(R.id.fab_edit_task_done);
    fab.setImageResource(R.drawable.ic_done);
    fab.setOnClickListener(setClickListener);
}
 
Example 16
Source File: UserDetailActivity.java    From Ruisi with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_user_detail);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.transparent));
    }
    collapsingToolbarLayout = findViewById(R.id.toolbar_layout);
    infoList = findViewById(R.id.recycler_view);
    CircleImageView imageView = findViewById(R.id.user_detail_img_avatar);
    coordinatorLayout = findViewById(R.id.main_window);
    progressView = findViewById(R.id.grade_progress);
    progressText = findViewById(R.id.progress_text);
    FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(v -> fabClick());

    ViewCompat.setTransitionName(imageView, NAME_IMG_AVATAR);
    username = getIntent().getStringExtra("loginName");
    imageUrl = getIntent().getStringExtra("avatarUrl");

    int uid = GetId.getNumber(imageUrl);

    Picasso.get().load(imageUrl).placeholder(R.drawable.image_placeholder).into(imageView);

    collapsingToolbarLayout.setTitle(username);
    Toolbar mToolbar = findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    adapter = new SimpleListAdapter(ListType.INFO, this, datas);
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
    infoList.setLayoutManager(layoutManager);
    infoList.addItemDecoration(new MyListDivider(this, MyListDivider.VERTICAL));
    adapter.setClickListener((v, position) -> {
        if (position == 0 && App.isLogin(UserDetailActivity.this)) {
            Intent intent = new Intent(UserDetailActivity.this, FragementActivity.class);
            intent.putExtra("TYPE", FrageType.TOPIC);
            intent.putExtra("username", username);
            if (uid > 0) {
                intent.putExtra("uid", uid);
            }

            UserDetailActivity.this.startActivity(intent);
        }
    });
    infoList.setAdapter(adapter);

    userUid = getIntent().getStringExtra("uid");
    if (TextUtils.isEmpty(userUid)) {
        userUid = GetId.getId("uid=", imageUrl);
    }

    //如果是自己
    if (userUid.equals(App.getUid(this))) {
        fab.setImageResource(R.drawable.ic_exit_to_app_24dp);
        imageView.setOnClickListener(view -> {
            final String[] items = {"修改密码"};
            AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
            alertBuilder.setTitle("操作");
            alertBuilder.setItems(items, (arg0, index) -> {
                if (index == 0) {
                    startActivity(new Intent(UserDetailActivity.this, ChangePasswordActivity.class));
                }
            });
            AlertDialog d = alertBuilder.create();
            d.show();
        });

    }
    loadData(UrlUtils.getUserHomeUrl(userUid, false));
}
 
Example 17
Source File: FloatingActionButtonBindingAdapter.java    From deagle with Apache License 2.0 4 votes vote down vote up
@BindingAdapter("src") public static void setImageRes(final FloatingActionButton fab, final @DrawableRes int drawable) {
	fab.setImageResource(drawable);
}
 
Example 18
Source File: TaskDetailKey.java    From simple-stack with Apache License 2.0 4 votes vote down vote up
@Override
protected void setupFab(Fragment fragment, FloatingActionButton fab) {
    fab.setImageResource(R.drawable.ic_edit);
    fab.setOnClickListener(v -> ((TaskDetailFragment) fragment).startEditTask());
}
 
Example 19
Source File: AddEditTaskKey.java    From simple-stack with Apache License 2.0 4 votes vote down vote up
@Override
protected void setupFab(Fragment fragment, FloatingActionButton fab) {
    fab.setImageResource(R.drawable.ic_done);
    fab.setOnClickListener(v -> ((AddEditTaskFragment) fragment).saveTask());
}
 
Example 20
Source File: TasksKey.java    From simple-stack with Apache License 2.0 4 votes vote down vote up
@Override
protected void setupFab(Fragment fragment, FloatingActionButton fab) {
    fab.setImageResource(R.drawable.ic_add);
    fab.setOnClickListener(v -> ((TasksFragment) fragment).addNewTask());
}