Java Code Examples for com.google.android.flexbox.FlexboxLayout#addView()

The following examples show how to use com.google.android.flexbox.FlexboxLayout#addView() . 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: FlexboxBindingAdapter.java    From WanAndroid with GNU General Public License v3.0 6 votes vote down vote up
@BindingAdapter(value = {"fullFlexData", "postTreeViewModel"})
public static void fullFlexData(FlexboxLayout layout, TreeBean treeBean, PostTreeViewModel viewModel) {
    layout.removeAllViews();
    if (treeBean.getChildren() == null || treeBean.getChildren().size() == 0) return;
    Context context = layout.getContext();
    for (TreeBean tree : treeBean.getChildren()) {
        TextView textView = new TextView(context);
        textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewHelper.dpToPx(context, 40)));
        textView.setTextColor(ContextCompat.getColor(context, R.color.textSecondary));
        textView.setBackgroundResource(R.drawable.btn_rounded_outline);
        textView.setGravity(Gravity.CENTER);
        textView.setFocusable(true);
        textView.setClickable(true);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            textView.setForeground(ContextCompat.getDrawable(context, R.drawable.ripple_theme_small));
        }
        textView.setText(tree.getName());
        textView.setOnClickListener(v -> viewModel.mTagClickEvent.setValue(treeBean.setCheckedChild(tree)));
        layout.addView(textView);
    }
}
 
Example 2
Source File: ReadFragment.java    From GankGirl with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void onDataChild(List<ReadChildTypeBean> datas) {
    View mHeaderView = inflate(getContext(), R.layout.recycler_header_read, null);
    FlexboxLayout flexboxLayout = findById(mHeaderView, R.id.flexboxLayout);
    if (flexboxLayout.getRootView() == null)
        return;
    flexboxLayout.removeAllViews();

    for (ReadChildTypeBean data : datas) {
        ImageView imageView = new ImageView(getContext());
        FlexboxLayout.LayoutParams layoutParams = new FlexboxLayout.LayoutParams(DensityUtils.dip2px(getContext(), 30), DensityUtils.dip2px(getContext(), 30));
        imageView.setLayoutParams(layoutParams);
        imageView.setOnClickListener(v -> ReadMoreActivity.start(getContext(),data.getUrl(),data.getTitle(),data.getImg()));
        flexboxLayout.addView(imageView);

        int size = DensityUtils.dip2px(getContext(), 10);
        FlexboxLayout.LayoutParams layoutParam = (FlexboxLayout.LayoutParams) imageView
                .getLayoutParams();
        layoutParam.setMargins(size, size, size, 0);
        imageView.setLayoutParams(layoutParam);
        GlideImageLoader.loadAdapterCircle(getContext(), data.getImg(), imageView);
    }
    RecyclerViewUtils.setHeaderView(recyclerView, mHeaderView);
}
 
Example 3
Source File: OverlayController.java    From talkback with Apache License 2.0 6 votes vote down vote up
/**
 * Adds extra empty items to the bottom row of the menu overlay so spacing works. We want the
 * FlexboxLayout to justify items (i.e. center all rows that have the maximum number of items and
 * left-align the last row if it has fewer than the maximum number of items), but the closest
 * option is to center-align, so we artificially left-align the bottom row.
 */
@VisibleForTesting
void fillRemainingSpaceForMenuOverlay() {
  FlexboxLayout menuButtonsLayout = (FlexboxLayout) menuOverlay.findViewById(R.id.menu_buttons);
  int numActiveButtons = menuButtonsLayout.getFlexItemCount();
  int numRows = menuButtonsLayout.getFlexLines().size();
  if (numRows > 1) {
    int maxItemsPerRow = menuButtonsLayout.getFlexLines().get(0).getItemCountNotGone();
    int numButtonsInLastRow = numActiveButtons % maxItemsPerRow;
    if (numButtonsInLastRow > 0) {
      for (int i = numButtonsInLastRow; i < maxItemsPerRow; i++) {
        menuButtonsLayout.addView(new MenuButton(menuOverlay.getContext()));
      }
    }
  } else if (numRows == 1) {
    // TODO: Investigate if we can resize the menu horizontally when there's only one
    // row.
    // Hide the view until the spacing is figured out.
    menuOverlay.getRootView().setVisibility(View.INVISIBLE);
    fillOutSingleRow(menuOverlay, menuButtonsLayout);
  }
}
 
Example 4
Source File: OverlayController.java    From talkback with Apache License 2.0 6 votes vote down vote up
private boolean drawNewMenuButtons() {
  if (firstMenuItemIndex < 0 || menuItems.size() <= firstMenuItemIndex) {
    clearAllOverlays();
    return false;
  }

  // Adds the new menu items into a newly drawn menu.
  FlexboxLayout menuButtonsLayout = (FlexboxLayout) menuOverlay.findViewById(R.id.menu_buttons);
  menuButtonsLayout.removeAllViews();
  for (int i = firstMenuItemIndex; i < lastMenuItemIndex; i++) {
    MenuItem menuItem = menuItems.get(i);
    MenuButton button = new MenuButton(getContext());
    setIconTextAndOnClickListenerForMenuButton(button, menuItem);
    menuButtonsLayout.addView(button);
  }

  // Cancel button. Always visible.
  setIconTextAndOnClickListenerForCancelButton();
  return true;
}
 
Example 5
Source File: MyDetailsOverviewRowPresenter.java    From jellyfin-androidtv with GNU General Public License v2.0 5 votes vote down vote up
private void addGenres(FlexboxLayout layout, BaseItemDto item) {
    layout.removeAllViews();
    if (item.getGenres() != null && item.getGenres().size() > 0) {
        boolean first = true;
        for (String genre : item.getGenres()) {
            if (!first) InfoLayoutHelper.addSpacer(TvApp.getApplication().getCurrentActivity(), layout, "  /  ", 12);
            first = false;
            layout.addView(new GenreButton(layout.getContext(), 14, genre, item.getBaseItemType()));
        }
    }
}
 
Example 6
Source File: ItemListActivity.java    From jellyfin-androidtv with GNU General Public License v2.0 5 votes vote down vote up
private void addGenres(FlexboxLayout layout) {
    if (mBaseItem.getGenres() != null && mBaseItem.getGenres().size() > 0) {
        boolean first = true;
        for (String genre : mBaseItem.getGenres()) {
            if (!first) InfoLayoutHelper.addSpacer(this, layout, "  /  ", 14);
            first = false;
            layout.addView(new GenreButton(this, 16, genre, mBaseItem.getBaseItemType()));
        }
    }
}
 
Example 7
Source File: SponsorsFragment.java    From droidkaigi2016 with Apache License 2.0 5 votes vote down vote up
private void addView(Sponsor sponsor, FlexboxLayout container) {
    SponsorImageView imageView = new SponsorImageView(getActivity());
    imageView.bindData(sponsor, v -> {
        if (TextUtils.isEmpty(sponsor.url))
            return;
        analyticsTracker.sendEvent("sponsor", sponsor.url);
        AppUtil.showWebPage(getActivity(), sponsor.url);
    });
    FlexboxLayout.LayoutParams params = new FlexboxLayout.LayoutParams(
            FlexboxLayout.LayoutParams.WRAP_CONTENT, FlexboxLayout.LayoutParams.WRAP_CONTENT);
    int margin = (int) getResources().getDimension(R.dimen.spacing_small);
    params.setMargins(margin, margin, 0, 0);
    container.addView(imageView, params);
}
 
Example 8
Source File: TreeAdapter.java    From CloudReader with Apache License 2.0 5 votes vote down vote up
@Override
protected void bindView(BaseByViewHolder<TreeItemBean> holder, TreeItemBean dataBean, int position) {
    if (dataBean != null) {
        TextView tvTreeTitle = holder.getView(R.id.tv_tree_title);
        FlexboxLayout flTree = holder.getView(R.id.fl_tree);
        String name = DataUtil.getHtmlString(dataBean.getName());
        if (isSelect) {
            flTree.setVisibility(View.GONE);
            if (selectedPosition == position) {
                name = name + "     ★★★";
                tvTreeTitle.setTextColor(CommonUtils.getColor(R.color.colorTheme));
            } else {
                tvTreeTitle.setTextColor(CommonUtils.getColor(R.color.colorContent));
            }
        } else {
            tvTreeTitle.setTextColor(CommonUtils.getColor(R.color.colorContent));
            flTree.setVisibility(View.VISIBLE);
            for (int i = 0; i < dataBean.getChildren().size(); i++) {
                WxarticleItemBean childItem = dataBean.getChildren().get(i);
                TextView child = createOrGetCacheFlexItemTextView(flTree);
                child.setText(DataUtil.getHtmlString(childItem.getName()));
                child.setOnClickListener(v -> CategoryDetailActivity.start(v.getContext(), childItem.getId(), dataBean));
                flTree.addView(child);
            }
        }
        tvTreeTitle.setText(ThinBoldSpan.getDefaultSpanString(tvTreeTitle.getContext(), name));
    }
}
 
Example 9
Source File: OverlayController.java    From talkback with Apache License 2.0 5 votes vote down vote up
private static void fillOutSingleRow(SimpleOverlay overlay, FlexboxLayout menuButtonsLayout) {
  menuButtonsLayout.addView(new MenuButton(overlay.getContext()));
  overlay
      .getRootView()
      .post(
          () -> {
            if (menuButtonsLayout.getFlexLines().size() > 1) {
              menuButtonsLayout.removeViewAt(menuButtonsLayout.getFlexItemCount() - 1);
              overlay.getRootView().setVisibility(View.VISIBLE);
            } else {
              fillOutSingleRow(overlay, menuButtonsLayout);
            }
          });
}
 
Example 10
Source File: SponsorsFragment.java    From droidkaigi2016 with Apache License 2.0 5 votes vote down vote up
private void addView(Sponsor sponsor, FlexboxLayout container) {
    SponsorImageView imageView = new SponsorImageView(getActivity());
    imageView.bindData(sponsor, v -> {
        if (TextUtils.isEmpty(sponsor.url))
            return;
        analyticsTracker.sendEvent("sponsor", sponsor.url);
        AppUtil.showWebPage(getActivity(), sponsor.url);
    });
    FlexboxLayout.LayoutParams params = new FlexboxLayout.LayoutParams(
            FlexboxLayout.LayoutParams.WRAP_CONTENT, FlexboxLayout.LayoutParams.WRAP_CONTENT);
    int margin = (int) getResources().getDimension(R.dimen.spacing_small);
    params.setMargins(margin, margin, 0, 0);
    container.addView(imageView, params);
}
 
Example 11
Source File: InfoLayoutHelper.java    From jellyfin-androidtv with GNU General Public License v2.0 4 votes vote down vote up
public static void addSpacer(Activity activity, FlexboxLayout layout, String sp, int size) {
    TextView mSpacer = new TextView(activity);
    mSpacer.setTextSize(size);
    mSpacer.setText(sp);
    layout.addView(mSpacer);
}
 
Example 12
Source File: MyFabFragment.java    From FabulousFilter with Apache License 2.0 4 votes vote down vote up
private void inflateLayoutWithFilters(final String filter_category, FlexboxLayout fbl) {
    List<String> keys = new ArrayList<>();
    switch (filter_category) {
        case "genre":
            keys = ((MainActivity) getActivity()).getmData().getUniqueGenreKeys();
            break;
        case "rating":
            keys = ((MainActivity) getActivity()).getmData().getUniqueRatingKeys();
            break;
        case "year":
            keys = ((MainActivity) getActivity()).getmData().getUniqueYearKeys();
            break;
        case "quality":
            keys = ((MainActivity) getActivity()).getmData().getUniqueQualityKeys();
            break;
    }

    for (int i = 0; i < keys.size(); i++) {
        View subchild = getActivity().getLayoutInflater().inflate(R.layout.single_chip, null);
        final TextView tv = ((TextView) subchild.findViewById(R.id.txt_title));
        tv.setText(keys.get(i));
        final int finalI = i;
        final List<String> finalKeys = keys;
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (tv.getTag() != null && tv.getTag().equals("selected")) {
                    tv.setTag("unselected");
                    tv.setBackgroundResource(R.drawable.chip_unselected);
                    tv.setTextColor(ContextCompat.getColor(getContext(), R.color.filters_chips));
                    removeFromSelectedMap(filter_category, finalKeys.get(finalI));
                } else {
                    tv.setTag("selected");
                    tv.setBackgroundResource(R.drawable.chip_selected);
                    tv.setTextColor(ContextCompat.getColor(getContext(), R.color.filters_header));
                    addToSelectedMap(filter_category, finalKeys.get(finalI));
                }
            }
        });
        try {
            Log.d("k9res", "key: " + filter_category + " |val:" + keys.get(finalI));
            Log.d("k9res", "applied_filters != null: " + (applied_filters != null));
            Log.d("k9res", "applied_filters.get(key) != null: " + (applied_filters.get(filter_category) != null));
            Log.d("k9res", "applied_filters.get(key).contains(keys.get(finalI)): " + (applied_filters.get(filter_category).contains(keys.get(finalI))));
        } catch (Exception e) {

        }
        if (applied_filters != null && applied_filters.get(filter_category) != null && applied_filters.get(filter_category).contains(keys.get(finalI))) {
            tv.setTag("selected");
            tv.setBackgroundResource(R.drawable.chip_selected);
            tv.setTextColor(ContextCompat.getColor(getContext(), R.color.filters_header));
        } else {
            tv.setBackgroundResource(R.drawable.chip_unselected);
            tv.setTextColor(ContextCompat.getColor(getContext(), R.color.filters_chips));
        }
        textviews.add(tv);

        fbl.addView(subchild);
    }


}
 
Example 13
Source File: TopicPermissionsFragment.java    From tindroid with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
// onResume sets up the form with values and views which do not change + sets up listeners.
public void onResume() {
    super.onResume();

    final Activity activity = getActivity();
    final Bundle args = getArguments();

    if (activity == null || args == null) {
        return;
    }

    String name = args.getString("topic");
    mTopic = (ComTopic<VxCard>) Cache.getTinode().getTopic(name);
    if (mTopic == null) {
        Log.d(TAG, "TopicPermissions resumed with null topic.");
        activity.finish();
        return;
    }

    final View defaultPermissions = activity.findViewById(R.id.defaultPermissionsWrapper);
    final View tagManager = activity.findViewById(R.id.tagsManagerWrapper);

    if (mTopic.isGrpType()) {
        // Group topic

        activity.findViewById(R.id.singleUserPermissions).setVisibility(View.VISIBLE);
        activity.findViewById(R.id.p2pPermissions).setVisibility(View.GONE);

        if (mTopic.isOwner()) {
            tagManager.setVisibility(View.VISIBLE);
            tagManager.findViewById(R.id.buttonManageTags)
                    .setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    showEditTags();
                }
            });

            LayoutInflater inflater = LayoutInflater.from(activity);
            FlexboxLayout tagsView = activity.findViewById(R.id.tagList);
            tagsView.removeAllViews();

            String[] tags = mTopic.getTags();
            if (tags != null) {
                for (String tag : tags) {
                    TextView label = (TextView) inflater.inflate(R.layout.tag, tagsView, false);
                    label.setText(tag);
                    tagsView.addView(label);
                }
            }

        } else {
            tagManager.setVisibility(View.GONE);
        }

        defaultPermissions.setVisibility(mTopic.isManager() ? View.VISIBLE : View.GONE);

    } else {
        // P2P topic
        tagManager.setVisibility(View.GONE);

        activity.findViewById(R.id.singleUserPermissions).setVisibility(View.GONE);
        activity.findViewById(R.id.p2pPermissions).setVisibility(View.VISIBLE);

        VxCard two = mTopic.getPub();
        ((TextView) activity.findViewById(R.id.userTwoLabel)).setText(two != null && two.fn != null ?
                two.fn : mTopic.getName());

        defaultPermissions.setVisibility(View.GONE);
    }

    notifyContentChanged();
    notifyDataSetChanged();
}