com.google.android.flexbox.FlexboxLayoutManager Java Examples

The following examples show how to use com.google.android.flexbox.FlexboxLayoutManager. 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: SearchSuggestFragment.java    From playa with MIT License 6 votes vote down vote up
@Override
public void onFragmentViewCreated() {
    super.onFragmentViewCreated();
    if (presenter == null) {
        return;
    }
    presenter.attachView(this);

    hotSearchRecyclerView.setLayoutManager(new FlexboxLayoutManager(context));
    hotKeyAdapter = new HotKeyAdapter();
    hotSearchRecyclerView.setAdapter(hotKeyAdapter);

    searchHistoryRecyclerView.setLayoutManager(new LinearLayoutManager(context));
    searchHistoryAdapter = new SearchHistoryAdapter();
    searchHistoryRecyclerView.setAdapter(searchHistoryAdapter);

    presenter.getHotKey();
    presenter.getSearchHistory();
}
 
Example #2
Source File: AlertAdapter.java    From rally with Apache License 2.0 6 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    AlertHolder ah = (AlertHolder) holder;
    Alert a = mAlerts.get(position);
    ah.text.setText(a.getText());
    ah.icon.setImageResource(a.getIconId());

    ViewGroup.LayoutParams lp = ah.itemView.getLayoutParams();
    if (lp instanceof FlexboxLayoutManager.LayoutParams) {
        FlexboxLayoutManager.LayoutParams flexboxLp = (FlexboxLayoutManager.LayoutParams) lp;
        flexboxLp.setFlexGrow(0.1f);

        if (mUseNarrowMinWidth) {
            flexboxLp.setMinWidth(Math.round(NARROW_MIN_WIDTH_DP * mDensity));
            flexboxLp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
            ah.text.setTextSize(TypedValue.COMPLEX_UNIT_SP, LARGE_ALERT_FONT_SIZE_SP);
        } else {
            flexboxLp.setMinWidth(Math.round(MIN_WIDTH_DP * mDensity));
            flexboxLp.height = Math.round(MIN_HEIGHT_DP * mDensity);
            ah.text.setTextSize(TypedValue.COMPLEX_UNIT_SP, ALERT_FONT_SIZE_SP);
        }
    }
}
 
Example #3
Source File: ObservationFormPickerActivity.java    From mage-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_observation_form_picker);

    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.forms);

    FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(this);
    layoutManager.setFlexDirection(FlexDirection.ROW);
    layoutManager.setJustifyContent(JustifyContent.CENTER);
    recyclerView.setLayoutManager(layoutManager);

    JsonArray formDefinitions = EventHelper.getInstance(getApplicationContext()).getCurrentEvent().getNonArchivedForms();
    Adapter adapter = new Adapter(this, formDefinitions);
    recyclerView.setAdapter(adapter);

    findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            cancel(v);
        }
    });

    MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
}
 
Example #4
Source File: VerifyMnemonicBackupActivity.java    From Upchain-wallet with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void initDatas() {
    walletId = getIntent().getLongExtra("walletId", -1);
    walletMnemonic = getIntent().getStringExtra("walletMnemonic");

    LogUtils.d("VerifyMnemonicBackUp", "walletMnemonic:" + walletMnemonic);

    String[] words = walletMnemonic.split("\\s+");
    mnemonicWords = new ArrayList<>();
    for (int i = 0; i < words.length; i++) {
        VerifyMnemonicWordTag verifyMnemonicWordTag = new VerifyMnemonicWordTag();
        verifyMnemonicWordTag.setMnemonicWord(words[i]);
        mnemonicWords.add(verifyMnemonicWordTag);
    }
    // 乱序
    Collections.shuffle(mnemonicWords);

    // 未选中单词
    FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(this);
    layoutManager.setFlexWrap(FlexWrap.WRAP);
    layoutManager.setAlignItems(AlignItems.STRETCH);
    rvMnemonic.setLayoutManager(layoutManager);
    verifyBackupMenmonicWordsAdapter = new VerifyBackupMnemonicWordsAdapter(R.layout.list_item_mnemoic, mnemonicWords);
    rvMnemonic.setAdapter(verifyBackupMenmonicWordsAdapter);


    // 已选中单词
    FlexboxLayoutManager layoutManager2 = new FlexboxLayoutManager(this);
    layoutManager2.setFlexWrap(FlexWrap.WRAP);
    layoutManager2.setAlignItems(AlignItems.STRETCH);
    rvSelected.setLayoutManager(layoutManager2);
    selectedMnemonicWords = new ArrayList<>();
    verifyBackupSelectedMnemonicWordsAdapter = new VerifyBackupSelectedMnemonicWordsAdapter(R.layout.list_item_mnemoic_selected, selectedMnemonicWords);
    rvSelected.setAdapter(verifyBackupSelectedMnemonicWordsAdapter);
}
 
Example #5
Source File: NameFormatBuilderDialogFragment.java    From SAI with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onContentViewCreated(View view, @Nullable Bundle savedInstanceState) {
    revealBottomSheet();
    setTitle(R.string.name_format_builder_title);

    getNegativeButton().setOnClickListener((v) -> dismiss());
    getPositiveButton().setOnClickListener((v) -> {
        deliverFormatAndDismiss(mViewModel.getFormat().getValue().build());
    });

    RecyclerView recycler = view.findViewById(R.id.rv_name_builder);

    FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(requireContext(), FlexDirection.ROW, FlexWrap.WRAP);
    layoutManager.setJustifyContent(JustifyContent.SPACE_AROUND);
    recycler.setLayoutManager(layoutManager);

    BackupNameFormatBuilderPartsAdapter adapter = new BackupNameFormatBuilderPartsAdapter(mViewModel.getSelection(), this, requireContext());
    adapter.setData(Arrays.asList(BackupNameFormatBuilder.Part.values()));
    recycler.setAdapter(adapter);

    TextView preview = view.findViewById(R.id.tv_name_builder_sample);

    mViewModel.getSelection().asLiveData().observe(this, (selection) -> getPositiveButton().setEnabled(selection.hasSelection()));
    mViewModel.getFormat().observe(this, (format) -> {
        preview.setText(format.getParts().isEmpty() ? getString(R.string.name_format_builder_preview_empty) : getString(R.string.name_format_builder_preview, BackupNameFormat.format(format.build(), mViewModel.getOwnMeta())));
    });
}
 
Example #6
Source File: SearchBookActivity.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("InflateParams")
@Override
protected void bindView() {
    cardSearch.setCardBackgroundColor(ThemeStore.primaryColorDark(this));
    initSearchView();
    setSupportActionBar(toolbar);
    setupActionBar();
    fabSearchStop.hide();
    fabSearchStop.setBackgroundTintList(Selector.colorBuild()
            .setDefaultColor(ThemeStore.accentColor(this))
            .setPressedColor(ColorUtil.darkenColor(ThemeStore.accentColor(this)))
            .create());
    llSearchHistory.setOnClickListener(null);
    rfRvSearchBooks.setRefreshRecyclerViewAdapter(searchBookAdapter, new LinearLayoutManager(this));
    refreshErrorView = LayoutInflater.from(this).inflate(R.layout.view_refresh_error, null);
    refreshErrorView.findViewById(R.id.tv_refresh_again).setOnClickListener(v -> {
        //刷新失败 ,重试
        toSearch();
    });
    rfRvSearchBooks.setNoDataAndRefreshErrorView(LayoutInflater.from(this).inflate(R.layout.view_refresh_no_data, null),
            refreshErrorView);

    searchBookAdapter.setItemClickListener((view, position) -> {
        String dataKey = String.valueOf(System.currentTimeMillis());
        Intent intent = new Intent(SearchBookActivity.this, BookDetailActivity.class);
        intent.putExtra("openFrom", BookDetailPresenter.FROM_SEARCH);
        intent.putExtra("data_key", dataKey);
        BitIntentDataManager.getInstance().putData(dataKey, searchBookAdapter.getItemData(position));
        startActivityByAnim(intent, android.R.anim.fade_in, android.R.anim.fade_out);
    });

    fabSearchStop.setOnClickListener(view -> {
        fabSearchStop.hide();
        mPresenter.stopSearch();
    });
    rvBookshelf.setLayoutManager(new FlexboxLayoutManager(this));
    rvBookshelf.setAdapter(searchBookshelfAdapter);
}
 
Example #7
Source File: DynamicLayoutUtils.java    From dynamic-support with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the {@link FlexboxLayoutManager} object for the given context.
 *
 * @param context The context to instantiate the layout manager.
 * @param flexDirection The flex direction attribute to the flex container.
 * @param justifyContent The justify content attribute to the flex container.
 * @param alignItems The align items attribute to the flex container.
 *
 * @return The {@link FlexboxLayoutManager} object for the given context.
 */
public static @NonNull FlexboxLayoutManager getFlexboxLayoutManager(
        @NonNull Context context, @FlexDirection int flexDirection,
        @JustifyContent  int justifyContent, @AlignItems int alignItems) {
    FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(context);
    layoutManager.setFlexDirection(flexDirection);
    layoutManager.setJustifyContent(justifyContent);
    layoutManager.setAlignItems(alignItems);

    return layoutManager;
}
 
Example #8
Source File: CatViewHolder.java    From customview-samples with Apache License 2.0 5 votes vote down vote up
public void setData(int drawableId){
    mIvImg.setImageResource(drawableId);
    ViewGroup.LayoutParams layoutParams = mIvImg.getLayoutParams();
    if(layoutParams instanceof FlexboxLayoutManager.LayoutParams){
        ((FlexboxLayoutManager.LayoutParams) layoutParams).setFlexGrow(1);
    }
}
 
Example #9
Source File: MultiCatTraitLayout.java    From Field-Book with GNU General Public License v2.0 5 votes vote down vote up
void bindTo() {
    ViewGroup.LayoutParams lp = mButton.getLayoutParams();
    if (lp instanceof FlexboxLayoutManager.LayoutParams) {
        FlexboxLayoutManager.LayoutParams flexboxLp = (FlexboxLayoutManager.LayoutParams) lp;
        flexboxLp.setFlexGrow(1.0f);
    }
}
 
Example #10
Source File: DealDetailsActivity.java    From FeatureAdapter with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  scope = openScopes(getApplication(), DealDetailsScopeSingleton.class, this);
  scope.installModules(
      new SmoothieActivityModule(this),
      new SmoothieAndroidXActivityModule(this),
      new FeatureAnimatorModule(),
      new FeatureItemDecorationModule());
  inject(this, scope);
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_with_recycler);
  ButterKnife.bind(this);

  List<FeatureController<SampleModel>> features =
      featureControllerListCreator.getFeatureControllerList();
  RxFeaturesAdapter<SampleModel> adapter = new RxFeaturesAdapter<>(features);

  recyclerView.setHasFixedSize(true);
  recyclerView.setLayoutManager(new FlexboxLayoutManager(this));
  recyclerView.setAdapter(adapter);
  recyclerView.setItemAnimator(new FeatureAdapterDefaultAnimator(featureAnimatorController));
  recyclerView.addItemDecoration(featureAdapterItemDecoration);

  compositeDisposable.add(clicks(refreshButton).subscribe(v -> refreshDeal(), this::logError));

  refreshButton.setOnClickListener(ignored -> refreshDeal());

  // listen for feature events
  compositeDisposable.add(
      featureEvents(features)
          .observeOn(computation())
          // Grox and Feature Adapter are different libraries
          // to combine the 2, we need a mechanism that, given a feature event,
          // we trigger a command. In our sample, and we recommend it as a good practice,
          // our Grox commands implement the FeatureEvent interface.
          // This is why, the cast below is required
          .cast(Command.class)
          .flatMap(Command<SampleModel>::actions)
          .subscribe(store::dispatch, this::logError));

  // propagate states to features
  compositeDisposable.add(
      states(store)
          .subscribeOn(computation())
          .to(adapter::updateFeatureItems)
          .subscribe(this::logFeatureUpdate, this::logError));

  // listen for new states
  compositeDisposable.add(
      states(store).observeOn(mainThread()).subscribe(this::reactToNewState, this::logError));

  if (store.getState().deal() == null) {
    refreshDeal();
  }
}
 
Example #11
Source File: PublishFormFragment.java    From lbry-android with MIT License 4 votes vote down vote up
public View onCreateView(@NonNull LayoutInflater inflater,
                         ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_publish_form, container, false);

    scrollView = root.findViewById(R.id.publish_form_scroll_view);
    progressLoadingChannels = root.findViewById(R.id.publish_form_loading_channels);
    progressPublish = root.findViewById(R.id.publish_form_publishing);
    channelSpinner = root.findViewById(R.id.publish_form_channel_spinner);
    mediaContainer = root.findViewById(R.id.publish_form_media_container);

    inputTagFilter = root.findViewById(R.id.form_tag_filter_input);
    noTagsView = root.findViewById(R.id.form_no_added_tags);
    noTagResultsView = root.findViewById(R.id.form_no_tag_results);

    textInlineAddressInvalid = root.findViewById(R.id.publish_form_inline_address_invalid);
    inlineDepositBalanceContainer = root.findViewById(R.id.publish_form_inline_balance_container);
    inlineDepositBalanceValue = root.findViewById(R.id.publish_form_inline_balance_value);

    cardVideoOptimization = root.findViewById(R.id.publish_form_video_opt_card);
    optimizationProgress = root.findViewById(R.id.publish_form_video_opt_progress);
    optimizationRealProgress = root.findViewById(R.id.publish_form_video_opt_real_progress);
    textOptimizationProgress = root.findViewById(R.id.publish_form_video_opt_progress_text);
    textOptimizationStatus = root.findViewById(R.id.publish_form_video_opt_status);
    textOptimizationElapsed = root.findViewById(R.id.publish_form_video_opt_elapsed);

    layoutExtraFields = root.findViewById(R.id.publish_form_extra_options_container);
    linkShowExtraFields = root.findViewById(R.id.publish_form_toggle_extra);
    layoutPrice = root.findViewById(R.id.publish_form_price_container);
    textNoPrice = root.findViewById(R.id.publish_form_no_price);
    switchPrice = root.findViewById(R.id.publish_form_price_switch);
    uploadProgress = root.findViewById(R.id.publish_form_thumbnail_upload_progress);
    imageThumbnail = root.findViewById(R.id.publish_form_thumbnail_preview);
    linkGenerateAddress = root.findViewById(R.id.publish_form_generate_address);

    inputTitle = root.findViewById(R.id.publish_form_input_title);
    inputDescription = root.findViewById(R.id.publish_form_input_description);
    inputPrice = root.findViewById(R.id.publish_form_input_price);
    inputAddress = root.findViewById(R.id.publish_form_input_address);
    inputDeposit = root.findViewById(R.id.publish_form_input_deposit);
    inputOtherLicenseDescription = root.findViewById(R.id.publish_form_input_license_other);
    layoutOtherLicenseDescription = root.findViewById(R.id.publish_form_license_other_layout);
    priceCurrencySpinner = root.findViewById(R.id.publish_form_currency_spinner);
    languageSpinner = root.findViewById(R.id.publish_form_language_spinner);
    licenseSpinner = root.findViewById(R.id.publish_form_license_spinner);

    linkPublishCancel = root.findViewById(R.id.publish_form_cancel);
    buttonPublish = root.findViewById(R.id.publish_form_publish_button);

    Context context = getContext();
    FlexboxLayoutManager flm1 = new FlexboxLayoutManager(context);
    FlexboxLayoutManager flm2 = new FlexboxLayoutManager(context);
    FlexboxLayoutManager flm3 = new FlexboxLayoutManager(context);
    addedTagsList = root.findViewById(R.id.form_added_tags);
    addedTagsList.setLayoutManager(flm1);
    suggestedTagsList = root.findViewById(R.id.form_suggested_tags);
    suggestedTagsList.setLayoutManager(flm2);

    root.findViewById(R.id.form_mature_tags_container).setVisibility(View.VISIBLE);
    matureTagsList = root.findViewById(R.id.form_mature_tags);
    matureTagsList.setLayoutManager(flm3);

    addedTagsAdapter = new TagListAdapter(new ArrayList<>(), context);
    addedTagsAdapter.setCustomizeMode(TagListAdapter.CUSTOMIZE_MODE_REMOVE);
    addedTagsAdapter.setClickListener(this);
    addedTagsList.setAdapter(addedTagsAdapter);

    suggestedTagsAdapter = new TagListAdapter(new ArrayList<>(), getContext());
    suggestedTagsAdapter.setCustomizeMode(TagListAdapter.CUSTOMIZE_MODE_ADD);
    suggestedTagsAdapter.setClickListener(this);
    suggestedTagsList.setAdapter(suggestedTagsAdapter);

    matureTagsAdapter = new TagListAdapter(Helper.getTagObjectsForTags(Predefined.MATURE_TAGS), context);
    matureTagsAdapter.setCustomizeMode(TagListAdapter.CUSTOMIZE_MODE_ADD);
    matureTagsAdapter.setClickListener(this);
    matureTagsList.setAdapter(matureTagsAdapter);

    inlineChannelCreator = root.findViewById(R.id.container_inline_channel_form_create);
    inlineChannelCreatorInputName = root.findViewById(R.id.inline_channel_form_input_name);
    inlineChannelCreatorInputDeposit = root.findViewById(R.id.inline_channel_form_input_deposit);
    inlineChannelCreatorInlineBalance = root.findViewById(R.id.inline_channel_form_inline_balance_container);
    inlineChannelCreatorInlineBalanceValue = root.findViewById(R.id.inline_channel_form_inline_balance_value);
    inlineChannelCreatorProgress = root.findViewById(R.id.inline_channel_form_create_progress);
    inlineChannelCreatorCancelLink = root.findViewById(R.id.inline_channel_form_cancel_link);
    inlineChannelCreatorCreateButton = root.findViewById(R.id.inline_channel_form_create_button);

    initUi();

    return root;
}
 
Example #12
Source File: SearchActivity.java    From UGank with GNU General Public License v3.0 4 votes vote down vote up
private void initView() {

        StatusBarUtil.immersive(this);
        StatusBarUtil.setPaddingSmart(this, mToolbarSearch);
        setSupportActionBar(mToolbarSearch);
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }
        mToolbarSearch.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        mEdSearch.addTextChangedListener(this);
        mEdSearch.setOnEditorActionListener(this);

        mSwipeRefreshLayoutSearch.setColorSchemeResources(
                R.color.colorSwipeRefresh1,
                R.color.colorSwipeRefresh2,
                R.color.colorSwipeRefresh3,
                R.color.colorSwipeRefresh4,
                R.color.colorSwipeRefresh5,
                R.color.colorSwipeRefresh6);
        mSwipeRefreshLayoutSearch.setRefreshing(false);
        mSwipeRefreshLayoutSearch.setEnabled(false);

        mSearchListAdapter = new SearchListAdapter(this);
        mRecyclerViewSearch.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerViewSearch.addItemDecoration(new RecycleViewDivider(this, LinearLayoutManager.HORIZONTAL));
        mRecyclerViewSearch.setAdapter(mSearchListAdapter);
        mRecyclerViewSearch.setOnLoadMoreListener(this);
        mRecyclerViewSearch.setEmpty();

        mHistoryListAdapter = new HistoryListAdapter(this);

        mHistoryListAdapter.setOnItemClickListener(this);
        mHistoryListAdapter.mData = null;
        mRecyclerViewHistory.setLayoutManager(new FlexboxLayoutManager());
        mRecyclerViewHistory.setAdapter(mHistoryListAdapter);

        mEmojiRainLayout.addEmoji(R.mipmap.emoji1);
        mEmojiRainLayout.addEmoji(R.mipmap.emoji2);
        mEmojiRainLayout.addEmoji(R.mipmap.emoji3);
        mEmojiRainLayout.addEmoji(R.mipmap.emoji4);
        mEmojiRainLayout.addEmoji(R.mipmap.emoji5);
        mEmojiRainLayout.addEmoji(R.mipmap.emoji6);

    }
 
Example #13
Source File: MultiCatTraitLayout.java    From Field-Book with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void loadLayout() {
    final String trait = getCurrentTrait().getTrait();
    getEtCurVal().setHint("");
    getEtCurVal().setVisibility(EditText.VISIBLE);

    if (!getNewTraits().containsKey(trait)) {
        getEtCurVal().setText("");
        getEtCurVal().setTextColor(Color.BLACK);
    } else {
        getEtCurVal().setText(getNewTraits().get(trait).toString());
        getEtCurVal().setTextColor(Color.parseColor(getDisplayColor()));
    }

    final String[] cat = getCurrentTrait().getCategories().split("/");

    FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(getContext());
    layoutManager.setFlexWrap(FlexWrap.WRAP);
    layoutManager.setFlexDirection(FlexDirection.ROW);
    layoutManager.setAlignItems(AlignItems.STRETCH);
    gridMultiCat.setLayoutManager(layoutManager);

    if (!((CollectActivity) getContext()).isDataLocked()) {

        gridMultiCat.setAdapter(new MutlticatTraitAdapter(getContext()) {

            @Override
            public void onBindViewHolder(MulticatTraitViewHolder holder, int position) {
                holder.bindTo();
                holder.mButton.setText(cat[position]);
                holder.mButton.setOnClickListener(createClickListener(holder.mButton,position));
                if (hasCategory(cat[position], getEtCurVal().getText().toString()))
                    pressOnButton(holder.mButton);
            }

            @Override
            public int getItemCount() {
                return cat.length;
            }
        });
    }

    gridMultiCat.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            gridMultiCat.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            View lastChild = gridMultiCat.getChildAt(gridMultiCat.getChildCount() - 1);
            gridMultiCat.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, lastChild.getBottom()));
        }
    });
}