com.google.android.flexbox.FlexboxLayout Java Examples

The following examples show how to use com.google.android.flexbox.FlexboxLayout. 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: CreateChatFragment.java    From weMessage with GNU Affero General Public License v3.0 6 votes vote down vote up
public void initializeView(){
    FlexboxLayout.LayoutParams layoutParams = (FlexboxLayout.LayoutParams) getLayoutParams();
    int paddingPxVer = DisplayUtils.convertDpToRoundedPixel(paddingVerticalDp, getContext());
    int paddingPxHoz = DisplayUtils.convertDpToRoundedPixel(paddingHorizontalDp, getContext());

    layoutParams.setMarginStart(DisplayUtils.convertDpToRoundedPixel(marginHorizontalDp, getContext()));
    layoutParams.setMarginEnd(DisplayUtils.convertDpToRoundedPixel(marginHorizontalDp, getContext()));

    setFont("OrkneyLight");
    setTextSize(16);
    setTextColor(getResources().getColor(R.color.colorHeader));
    setFilters(new InputFilter[] { new InputFilter.LengthFilter(32) });
    setEllipsize(TextUtils.TruncateAt.END);
    setLayoutParams(layoutParams);
    setPadding(paddingPxHoz, paddingPxVer, paddingPxHoz, paddingPxVer);

    setOnClickListener(this);
}
 
Example #2
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 #3
Source File: OverlayController.java    From talkback with Apache License 2.0 6 votes vote down vote up
private void updateVisibleMenuButtons() {
  FlexboxLayout menuButtonsLayout = (FlexboxLayout) menuOverlay.findViewById(R.id.menu_buttons);
  int numNewMenuItems = lastMenuItemIndex - firstMenuItemIndex;
  int numMenuButtons = menuButtonsLayout.getFlexItemCount();
  for (int i = 0; i < numMenuButtons; i++) {
    MenuButton button = (MenuButton) menuButtonsLayout.getFlexItemAt(i);
    if (i < numNewMenuItems) {
      // Replace existing menu buttons with new ones.
      MenuItem newMenuItem = menuItems.get(firstMenuItemIndex + i);
      setIconTextAndOnClickListenerForMenuButton(button, newMenuItem);
    } else if (button != null) {
      // Clear now-unused buttons.
      button.clearButton();
    }
  }
}
 
Example #4
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 #5
Source File: OverlayController.java    From talkback with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
void updateMenuContent(List<MenuItem> newMenuItems) {
  menuItems = newMenuItems;
  firstMenuItemIndex = 0;
  FlexboxLayout menuButtonsLayout = (FlexboxLayout) menuOverlay.findViewById(R.id.menu_buttons);
  int maxItemsPerPage = menuButtonsLayout.getFlexItemCount();
  View nextArrow = menuOverlay.findViewById(R.id.next_arrow_button);
  if (maxItemsPerPage < menuItems.size()) {
    nextArrow.setVisibility(View.VISIBLE);
    lastMenuItemIndex = maxItemsPerPage;
  } else {
    nextArrow.setVisibility(View.INVISIBLE);
    lastMenuItemIndex = menuItems.size();
  }
  menuOverlay.findViewById(R.id.previous_arrow_button).setVisibility(View.INVISIBLE);
  updateVisibleMenuButtons();
}
 
Example #6
Source File: OverlayController.java    From talkback with Apache License 2.0 6 votes vote down vote up
/** Moves to the previous menu items in the menu, or does nothing if there are none. */
public void moveToPreviousMenuItems() {
  if (firstMenuItemIndex == 0) {
    return;
  }

  lastMenuItemIndex = firstMenuItemIndex;
  FlexboxLayout menuButtonsLayout = (FlexboxLayout) menuOverlay.findViewById(R.id.menu_buttons);
  firstMenuItemIndex = Math.max(0, firstMenuItemIndex - menuButtonsLayout.getFlexItemCount());
  updateVisibleMenuButtons();

  menuOverlay.findViewById(R.id.next_arrow_button).setVisibility(View.VISIBLE);
  if (firstMenuItemIndex == 0) {
    menuOverlay.findViewById(R.id.previous_arrow_button).setVisibility(View.INVISIBLE);
  }

  if (selectMenuItemListener != null) {
    selectMenuItemListener.onMenuItemSelected(
        SwitchAccessMenuItemEnum.MenuItem.MENU_BUTTON_PREVIOUS_SCREEN);
  }
}
 
Example #7
Source File: OverlayController.java    From talkback with Apache License 2.0 6 votes vote down vote up
/** Moves to the next set of menu items. Does nothing if no more items are present. */
private void moveToNextMenuItemsOrClearOverlays() {
  if (lastMenuItemIndex == menuItems.size()) {
    return;
  }

  firstMenuItemIndex = lastMenuItemIndex;
  FlexboxLayout menuButtonsLayout = (FlexboxLayout) menuOverlay.findViewById(R.id.menu_buttons);
  lastMenuItemIndex =
      Math.min(menuItems.size(), lastMenuItemIndex + menuButtonsLayout.getFlexItemCount());
  updateVisibleMenuButtons();

  menuOverlay.findViewById(R.id.previous_arrow_button).setVisibility(View.VISIBLE);
  if (lastMenuItemIndex == menuItems.size()) {
    menuOverlay.findViewById(R.id.next_arrow_button).setVisibility(View.INVISIBLE);
  }

  if (selectMenuItemListener != null) {
    selectMenuItemListener.onMenuItemSelected(
        SwitchAccessMenuItemEnum.MenuItem.MENU_BUTTON_NEXT_SCREEN);
  }
}
 
Example #8
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 #9
Source File: PassWordInputLayout.java    From AndroidProjects with MIT License 6 votes vote down vote up
private void addValidatedPassphraseToView(final List<Pair<Boolean, String>> validatedPassphrase) {
    if (validatedPassphrase.size() == 0) return;
    final FlexboxLayout wrapper = findViewById(R.id.wrapper);
    for (int i = 0; i < validatedPassphrase.size(); i++) {
        final SuggestionInputLayout inputView = (SuggestionInputLayout) wrapper.getChildAt(i);
        final String word = validatedPassphrase.get(i).second;
        final boolean isApproved = validatedPassphrase.get(i).first;
        if (isApproved) {
            inputView.showTagView(word);
            addWordToPassphraseList(word, i);
        } else {
            inputView.showInputView(word);
            addWordToPassphraseList(null, i);
        }
        inputView.setVisibility(VISIBLE);
    }

    checkIfPassphraseIsApproved();
    this.currentCell = validatedPassphrase.size() - 1;
    findViewById(R.id.hint).setVisibility(GONE);
}
 
Example #10
Source File: PassWordInputLayout.java    From AndroidProjects with MIT License 6 votes vote down vote up
private void reAddWordsToInputViews() {
    if (this.passphraseList.size() == 0) return;

    final FlexboxLayout wrapper = findViewById(R.id.wrapper);

    for (int i = 0; i < this.passphraseList.size(); i++) {
        final SuggestionInputLayout inputView = (SuggestionInputLayout) wrapper.getChildAt(i);
        final String word = this.passphraseList.get(i);

        if (word != null) {
            inputView.showTagView(word);
        } else {
            inputView.showInputView(null);
        }
        inputView.setVisibility(VISIBLE);
    }

    checkIfPassphraseIsApproved();
}
 
Example #11
Source File: LayoutParamsCreator.java    From HtmlNative with Apache License 2.0 6 votes vote down vote up
public static void createLayoutParams(LayoutParamsCreator creator, ViewGroup.LayoutParams
        outParams) {
    outParams.height = creator.height;
    outParams.width = creator.width;
    if (outParams instanceof HNDivLayout.HNDivLayoutParams) {
        ((HNDivLayout.HNDivLayoutParams) outParams).setMargins(creator.marginLeft, creator
                .marginTop, creator.marginRight, creator.marginBottom);
        ((HNDivLayout.HNDivLayoutParams) outParams).positionMode = creator.positionMode;
        ((HNDivLayout.HNDivLayoutParams) outParams).left = creator.left;
        ((HNDivLayout.HNDivLayoutParams) outParams).top = creator.top;
        ((HNDivLayout.HNDivLayoutParams) outParams).bottom = creator.bottom;
        ((HNDivLayout.HNDivLayoutParams) outParams).right = creator.right;
    } else if (outParams instanceof FlexboxLayout.LayoutParams) {
        //TODO complete
    } else if (outParams instanceof ViewGroup.MarginLayoutParams) {
        ((ViewGroup.MarginLayoutParams) outParams).setMargins(creator.marginLeft, creator
                .marginTop, creator.marginRight, creator.marginBottom);

    } else {
        throw new IllegalArgumentException("can't create related layoutParams, unknown " +
                "layoutParams type " + outParams.toString());
    }
}
 
Example #12
Source File: StyleHandlerFactory.java    From HtmlNative with Apache License 2.0 6 votes vote down vote up
public static StyleHandler byClass(@NonNull Class<? extends View> clazz) {

        if (TextView.class.isAssignableFrom(clazz)) {
            return sText;
        } else if (ImageView.class.isAssignableFrom(clazz)) {
            return sImage;
        } else if (clazz.equals(HNDivLayout.class)) {
            return sDiv;
        } else if (clazz.equals(FlexboxLayout.class)) {
            return sFlex;
        } else if (clazz.equals(WebView.class)) {
            return sWebview;
        } else {
            return null;
        }
    }
 
Example #13
Source File: FlexBoxLayoutStyleHandler.java    From HtmlNative with Apache License 2.0 6 votes vote down vote up
@FlexboxLayout.JustifyContent
private static int justContent(java.lang.String content) {
    switch (content) {
        case "flex-start":
            return FlexboxLayout.JUSTIFY_CONTENT_FLEX_START;
        case "flex-end":
            return FlexboxLayout.JUSTIFY_CONTENT_FLEX_END;
        case "center":
            return FlexboxLayout.JUSTIFY_CONTENT_CENTER;
        case "space-between":
            return FlexboxLayout.JUSTIFY_CONTENT_SPACE_BETWEEN;
        case "space-around":
            return FlexboxLayout.JUSTIFY_CONTENT_SPACE_AROUND;
        default:
            return FlexboxLayout.JUSTIFY_CONTENT_FLEX_START;
    }
}
 
Example #14
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 #15
Source File: MyDetailsOverviewRowPresenter.java    From jellyfin-androidtv with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor for ViewHolder.
 *
 * @param rootView The View bound to the Row.
 */
public ViewHolder(View rootView) {
    super(rootView);
    mTitle = (TextView) rootView.findViewById(R.id.fdTitle);
    mTitle.setShadowLayer(5, 5, 5, Color.BLACK);
    mInfoTitle1 = (TextView) rootView.findViewById(R.id.infoTitle1);
    mInfoTitle2 = (TextView) rootView.findViewById(R.id.infoTitle2);
    mInfoTitle3 = (TextView) rootView.findViewById(R.id.infoTitle3);
    mInfoValue1 = (TextView) rootView.findViewById(R.id.infoValue1);
    mInfoValue2 = (TextView) rootView.findViewById(R.id.infoValue2);
    mInfoValue3 = (TextView) rootView.findViewById(R.id.infoValue3);

    mLeftFrame = (RelativeLayout) rootView.findViewById(R.id.leftFrame);

    mGenreRow = (FlexboxLayout) rootView.findViewById(R.id.fdGenreRow);
    mInfoRow =  (LinearLayout)rootView.findViewById(R.id.fdMainInfoRow);
    mPoster = (ImageView) rootView.findViewById(R.id.mainImage);
    //mStudioImage = (ImageView) rootView.findViewById(R.id.studioImage);
    mButtonRow = (LinearLayout) rootView.findViewById(R.id.fdButtonRow);
    mSummary = (TextView) rootView.findViewById(R.id.fdSummaryText);

}
 
Example #16
Source File: MyFabFragment.java    From FabulousFilter with Apache License 2.0 6 votes vote down vote up
@Override
        public Object instantiateItem(ViewGroup collection, int position) {
            LayoutInflater inflater = LayoutInflater.from(getContext());
            ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.view_filters_sorters, collection, false);
            FlexboxLayout fbl = (FlexboxLayout) layout.findViewById(R.id.fbl);
//            LinearLayout ll_scroll = (LinearLayout) layout.findViewById(R.id.ll_scroll);
//            FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) (metrics.heightPixels-(104*metrics.density)));
//            ll_scroll.setLayoutParams(lp);
            switch (position) {
                case 0:
                    inflateLayoutWithFilters("genre", fbl);
                    break;
                case 1:
                    inflateLayoutWithFilters("rating", fbl);
                    break;
                case 2:
                    inflateLayoutWithFilters("year", fbl);
                    break;
                case 3:
                    inflateLayoutWithFilters("quality", fbl);
                    break;
            }
            collection.addView(layout);
            return layout;

        }
 
Example #17
Source File: FlexBoxLayoutStyleHandler.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
@FlexboxLayout.FlexDirection
private static int flexDirection(@NonNull java.lang.String direction) {
    switch (direction) {
        case "getColumn-reverse":
            return FlexboxLayout.FLEX_DIRECTION_COLUMN_REVERSE;
        case "row-reverse":
            return FlexboxLayout.FLEX_DIRECTION_ROW_REVERSE;
        case "getColumn":
            return FlexboxLayout.FLEX_DIRECTION_COLUMN;
        default:
            return FlexboxLayout.FLEX_DIRECTION_ROW;
    }
}
 
Example #18
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 #19
Source File: IncomingMessageViewHolder.java    From weMessage with GNU Affero General Public License v3.0 5 votes vote down vote up
@JavascriptInterface
public void resizeInvisibleInk(final float height){
    if (getActivity() == null) return;

    getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            invisibleInkView.setLayoutParams(new FlexboxLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, (int) (height * getActivity().getResources().getDisplayMetrics().density * 1.2)));
        }
    });
}
 
Example #20
Source File: BackupKeyActivity.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
private TextView generateSeedWordTextView(String word) {
    int margin = Utils.dp2px(this, 4);
    int padding;
    float textSize;
    int textViewHeight;

    if (screenWidth > 800) {
        textSize = 16.0f;
        padding = Utils.dp2px(this, 20);
        textViewHeight = Utils.dp2px(this, 44);
    } else {
        textSize = 14.0f;
        padding = Utils.dp2px(this, 16);
        textViewHeight = Utils.dp2px(this, 38);
    }

    FlexboxLayout.LayoutParams params =
            new FlexboxLayout.LayoutParams(FlexboxLayout.LayoutParams.WRAP_CONTENT, textViewHeight);

    params.setMargins(margin, margin, margin, margin);
    TextView seedWord = new TextView(this);
    seedWord.setMaxLines(1);
    seedWord.setText(word);
    seedWord.setTypeface(ResourcesCompat.getFont(this, R.font.font_regular));
    seedWord.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
    seedWord.setBackgroundResource(R.drawable.background_seed_word);
    seedWord.setTextColor(getColor(R.color.mine));
    seedWord.setLayoutParams(params);
    seedWord.setGravity(Gravity.CENTER);
    seedWord.setPadding(padding, 0, padding, 0);

    return seedWord;
}
 
Example #21
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 #22
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 #23
Source File: TreeAdapter.java    From CloudReader with Apache License 2.0 5 votes vote down vote up
private TextView createOrGetCacheFlexItemTextView(FlexboxLayout fbl) {
    TextView tv = mFlexItemTextViewCaches.poll();
    if (tv != null) {
        return tv;
    }
    if (mInflater == null) {
        mInflater = LayoutInflater.from(fbl.getContext());
    }
    return (TextView) mInflater.inflate(R.layout.layout_tree_tag, fbl, false);
}
 
Example #24
Source File: TreeAdapter.java    From CloudReader with Apache License 2.0 5 votes vote down vote up
/**
 * 复用需要有相同的BaseByViewHolder,且HeaderView部分获取不到FlexboxLayout,需要容错
 */
@Override
public void onViewRecycled(@NonNull BaseByViewHolder<TreeItemBean> holder) {
    super.onViewRecycled(holder);
    FlexboxLayout fbl = holder.getView(R.id.fl_tree);
    if (fbl != null) {
        for (int i = 0; i < fbl.getChildCount(); i++) {
            mFlexItemTextViewCaches.offer((TextView) fbl.getChildAt(i));
        }
        fbl.removeAllViews();
    }
}
 
Example #25
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 #26
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 #27
Source File: SyntaxFragment.java    From android-docs-samples with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                         @Nullable Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_syntax, container, false);
    mLayout = (FlexboxLayout) view.findViewById(R.id.layout);
    TokenInfo[] tokens = (TokenInfo[]) getArguments().getParcelableArray(ARG_TOKENS);
    if (tokens != null) {
        showTokens(tokens);
    }
    return view;
}
 
Example #28
Source File: FlexBoxLayoutStyleHandler.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
@FlexboxLayout.FlexWrap
private static int flexWrap(java.lang.String wrap) {
    switch (wrap) {
        case "nowrap":
            return FlexboxLayout.FLEX_WRAP_NOWRAP;
        case "wrap":
            return FlexboxLayout.FLEX_WRAP_WRAP;
        case "wrap-reverse":
            return FlexboxLayout.FLEX_WRAP_WRAP_REVERSE;
        default:
            return FlexboxLayout.FLEX_WRAP_NOWRAP;
    }
}
 
Example #29
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 #30
Source File: LayoutParamsCreator.java    From HtmlNative with Apache License 2.0 5 votes vote down vote up
public static ViewGroup.LayoutParams createLayoutParams(View parent, LayoutParamsCreator
        creator) {
    if (parent instanceof HNDivLayout) {
        return creator.toHNDivLayoutParams();
    } else if (parent instanceof HNRootView) {
        return creator.toMarginLayoutParams();
    } else if (parent instanceof FlexboxLayout) {
        return creator.toFlexLayoutParams();
    } else {
        throw new IllegalArgumentException("can't create related layoutParams, unknown " +
                "view type " + parent.toString());
    }
}