Example usage for android.view ViewGroup setLayoutParams

List of usage examples for android.view ViewGroup setLayoutParams

Introduction

In this page you can find the example usage for android.view ViewGroup setLayoutParams.

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

From source file:org.zywx.wbpalmstar.plugin.uexiconlist.EUExIconList.java

/**
 * ??IconList view? ??//  w ww. j  av a  2 s . c  o  m
 * 
 */
private void resetFrame() {
    ((Activity) mContext).runOnUiThread(new Runnable() {

        @Override
        public void run() {
            if (mgr == null) {
                mgr = new LocalActivityManager((Activity) mContext, false);
                mgr.dispatchCreate(null);
            }
            Activity activity = mgr.getActivity(IconListActivity.TAG);
            if (activity != null) {
                ViewGroup subView = (ViewGroup) activity.getWindow().getDecorView();
                if (IconListOption.isFollowWebRoll()) {
                    AbsoluteLayout.LayoutParams lParams = (LayoutParams) subView.getLayoutParams();
                    lParams.width = (int) UIConfig.getScaleWidth();
                    lParams.height = (int) UIConfig.getScaleHight();
                    lParams.x = (int) UIConfig.getScaleX();
                    lParams.y = (int) UIConfig.getScaleY();
                    //                        AbsoluteLayout.LayoutParams lp = new AbsoluteLayout.LayoutParams(
                    //                                (int) UIConfig.getScaleWidth(),
                    //                                (int) UIConfig.getScaleHight(),
                    //                                (int) UIConfig.getScaleX(),
                    //                                (int) UIConfig.getScaleY());
                    subView.setLayoutParams(lParams);
                } else {
                    FrameLayout.LayoutParams lParams = (FrameLayout.LayoutParams) subView.getLayoutParams();
                    lParams.width = (int) UIConfig.getScaleWidth();
                    lParams.height = (int) UIConfig.getScaleHight();
                    lParams.leftMargin = (int) UIConfig.getScaleX();
                    lParams.topMargin = (int) UIConfig.getScaleY();
                    // FrameLayout.LayoutParams lp = new
                    // FrameLayout.LayoutParams(
                    // (int) UIConfig.getScaleWidth(),
                    // (int) UIConfig.getScaleHight());
                    // lp.leftMargin = (int) UIConfig.getScaleX();
                    // lp.topMargin = (int) UIConfig.getScaleY();
                    subView.setLayoutParams(lParams);
                }
                subView.invalidate();
                mEuExIconListHandler.send2Callback(WHAT_RESET_FRAME, null);
            }
        }
    });
}

From source file:gov.wa.wsdot.android.wsdot.ui.amtrakcascades.AmtrakCascadesSchedulesDetailsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    tf = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto-Regular.ttf");
    tfb = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto-Bold.ttf");

    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_recycler_with_textview_swipe_refresh, null);
    TextView schedule_title = root.findViewById(R.id.title);
    schedule_title.setTypeface(tfb);// w  w w.j  ava2 s .  co m

    if ((fromLocation.equalsIgnoreCase(toLocation))) {
        schedule_title.setText(amtrakStations.get(fromLocation));
    } else {
        schedule_title.setText("Departing: " + amtrakStations.get(fromLocation) + " and Arriving: "
                + amtrakStations.get(toLocation));
    }

    mRecyclerView = root.findViewById(R.id.my_recycler_view);
    mLayoutManager = new LinearLayoutManager(getActivity());
    mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mAdapter = new ScheduleAdapter(null);

    mRecyclerView.setAdapter(mAdapter);

    mRecyclerView.addItemDecoration(new SimpleDividerItemDecoration(getActivity()));

    // For some reason, if we omit this, NoSaveStateFrameLayout thinks we are
    // FILL_PARENT / WRAP_CONTENT, making the progress bar stick to the top of the activity.
    root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    swipeRefreshLayout = root.findViewById(R.id.swipe_container);
    swipeRefreshLayout.setOnRefreshListener(this);
    swipeRefreshLayout.setColorSchemeResources(R.color.holo_blue_bright, R.color.holo_green_light,
            R.color.holo_orange_light, R.color.holo_red_light);

    mEmptyView = root.findViewById(R.id.empty_list_view);

    viewModel = ViewModelProviders.of(this, viewModelFactory)
            .get(AmtrakCascadesSchedulesDetailsViewModel.class);

    viewModel.getResourceStatus().observe(this, resourceStatus -> {
        if (resourceStatus != null) {
            switch (resourceStatus.status) {
            case LOADING:
                swipeRefreshLayout.setRefreshing(true);
                break;
            case SUCCESS:
                swipeRefreshLayout.setRefreshing(false);
                break;
            case ERROR:
                swipeRefreshLayout.setRefreshing(false);
                TextView t = (TextView) mEmptyView;
                t.setText(R.string.no_connection);
                mEmptyView.setVisibility(View.VISIBLE);
                Toast.makeText(getContext(), "connection error", Toast.LENGTH_SHORT).show();
            }
        }
    });

    viewModel.getSchedule(statusDate, fromLocation, toLocation).observe(this, serviceItems -> {
        if (serviceItems != null) {
            mEmptyView.setVisibility(View.GONE);
            if (!serviceItems.isEmpty()) {
                mAdapter.setData(new ArrayList<>(serviceItems));
            } else {
                TextView t = (TextView) mEmptyView;
                t.setText("schedule unavailable.");
                mEmptyView.setVisibility(View.VISIBLE);
            }
        }
    });

    viewModel.refresh();

    return root;
}

From source file:com.grottworkshop.gwsmaterialviewpagerreg.MaterialViewPager.java

@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    //add @layout/material_view_pager_layout as child, containing all the MaterialViewPager views
    addView(LayoutInflater.from(getContext()).inflate(R.layout.material_view_pager_layout, this, false));

    headerBackgroundContainer = (ViewGroup) findViewById(R.id.headerBackgroundContainer);
    pagerTitleStripContainer = (ViewGroup) findViewById(R.id.pagerTitleStripContainer);
    /*//from w  w w  .  ja  v  a2s. com
    the layout containing logo
    default : empty
    with viewpager_logo you can set your own layout
    */
    ViewGroup logoContainer = (ViewGroup) findViewById(R.id.logoContainer);

    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mViewPager = (ViewPager) findViewById(R.id.viewPager);

    mViewPager.addOnPageChangeListener(this);

    //inflate subviews defined in attributes

    if (settings.headerLayoutId != -1) {
        headerBackgroundContainer.addView(LayoutInflater.from(getContext()).inflate(settings.headerLayoutId,
                headerBackgroundContainer, false));
    }

    if (isInEditMode()) { //preview titlestrip
        //add fake tabs on edit mode
        settings.pagerTitleStripId = R.layout.tools_material_view_pager_pagertitlestrip;
    }
    if (settings.pagerTitleStripId != -1) {
        pagerTitleStripContainer.addView(LayoutInflater.from(getContext()).inflate(settings.pagerTitleStripId,
                pagerTitleStripContainer, false));
    }

    if (settings.logoLayoutId != -1) {
        logoContainer.addView(
                LayoutInflater.from(getContext()).inflate(settings.logoLayoutId, logoContainer, false));
        if (settings.logoMarginTop != 0) {
            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) logoContainer
                    .getLayoutParams();
            layoutParams.setMargins(0, settings.logoMarginTop, 0, 0);
            logoContainer.setLayoutParams(layoutParams);
        }
    }

    headerBackground = findViewById(R.id.headerBackground);
    toolbarLayoutBackground = findViewById(R.id.toolbar_layout_background);

    initialiseHeights();

    //construct the materialViewPagerHeader with subviews
    if (!isInEditMode()) {
        materialViewPagerHeader = MaterialViewPagerHeader.withToolbar(mToolbar)
                .withToolbarLayoutBackground(toolbarLayoutBackground)
                .withPagerSlidingTabStrip(pagerTitleStripContainer).withHeaderBackground(headerBackground)
                .withStatusBackground(findViewById(R.id.statusBackground)).withLogo(logoContainer);

        //and construct the MaterialViewPagerAnimator
        //attach it to the activity to enable MaterialViewPagerHeaderView.setMaterialHeight();
        MaterialViewPagerHelper.register(getContext(), new MaterialViewPagerAnimator(this));
    } else {

        //if in edit mode, add fake cardsviews
        View sample = LayoutInflater.from(getContext()).inflate(R.layout.tools_list_items,
                pagerTitleStripContainer, false);

        FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) sample.getLayoutParams();
        int marginTop = Math.round(Utils.dpToPx(settings.headerHeight + 10, getContext()));
        params.setMargins(0, marginTop, 0, 0);
        super.setLayoutParams(params);

        addView(sample);
    }
}

From source file:gov.wa.wsdot.android.wsdot.ui.tollrates.SR167TollRatesFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_dynamic_toll_rates, null);

    mRecyclerView = root.findViewById(R.id.my_recycler_view);
    mRecyclerView.setHasFixedSize(true);
    mLayoutManager = new LinearLayoutManager(getActivity());
    mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mAdapter = new SR167TollRatesItemAdapter(getActivity());
    mRecyclerView.setAdapter(mAdapter);/*www.  java2 s .  c  o m*/

    mRecyclerView.addItemDecoration(new SimpleDividerItemDecoration(getActivity()));

    mRecyclerView.setPadding(0, 0, 0, 120);

    addDisclaimerView(root);

    directionRadioGroup = root.findViewById(R.id.segment_control);

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
    radioGroupDirectionIndex = sharedPref.getInt(getString(R.string.toll_rates_167_travel_direction_key), 0);

    if (radioGroupDirectionIndex == 0) {
        RadioButton leftSegment = root.findViewById(R.id.radio_left);
        leftSegment.setChecked(true);
    } else {
        RadioButton rightSegment = root.findViewById(R.id.radio_right);
        rightSegment.setChecked(true);
    }

    directionRadioGroup.setOnCheckedChangeListener((group, checkedId) -> {

        RadioButton selectedDirection = directionRadioGroup.findViewById(checkedId);

        mAdapter.setData(filterTollsForDirection(String.valueOf(selectedDirection.getText().charAt(0))));

        mLayoutManager.scrollToPositionWithOffset(0, 0);
        SharedPreferences sharedPref1 = PreferenceManager.getDefaultSharedPreferences(getContext());
        SharedPreferences.Editor editor = sharedPref1.edit();

        radioGroupDirectionIndex = directionRadioGroup.indexOfChild(selectedDirection);

        TextView travelTimeView = root.findViewById(R.id.travel_time_text);
        travelTimeView.setText(getTravelTimeStringForDirection(radioGroupDirectionIndex == 0 ? "N" : "S"));

        editor.putInt(getString(R.string.toll_rates_167_travel_direction_key), radioGroupDirectionIndex);

        editor.apply();

    });

    // For some reason, if we omit this, NoSaveStateFrameLayout thinks we are
    // FILL_PARENT / WRAP_CONTENT, making the progress bar stick to the top of the activity.
    root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    swipeRefreshLayout = root.findViewById(R.id.swipe_container);
    swipeRefreshLayout.setOnRefreshListener(this);
    swipeRefreshLayout.setColorSchemeResources(R.color.holo_blue_bright, R.color.holo_green_light,
            R.color.holo_orange_light, R.color.holo_red_light);

    mEmptyView = root.findViewById(R.id.empty_list_view);

    TextView header_link = root.findViewById(R.id.header_text);

    // create spannable string for underline
    SpannableString content = new SpannableString(
            getActivity().getResources().getString(R.string.sr167_info_link));
    content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
    header_link.setText(content);

    header_link.setTextColor(getResources().getColor(R.color.primary_default));
    header_link.setOnClickListener(v -> {
        Intent intent = new Intent();
        // GA tracker
        mTracker = ((WsdotApplication) getActivity().getApplication()).getDefaultTracker();
        mTracker.setScreenName("/Toll Rates/Learn about SR-167");
        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
        intent.setAction(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("https://www.wsdot.wa.gov/Tolling/SR167HotLanes/HOTtollrates.htm"));
        startActivity(intent);

    });

    viewModel = ViewModelProviders.of(this, viewModelFactory).get(TollRatesViewModel.class);

    viewModel.getResourceStatus().observe(this, resourceStatus -> {
        if (resourceStatus != null) {
            switch (resourceStatus.status) {
            case LOADING:
                swipeRefreshLayout.setRefreshing(true);
                break;
            case SUCCESS:
                swipeRefreshLayout.setRefreshing(false);
                break;
            case ERROR:
                swipeRefreshLayout.setRefreshing(false);
                Toast.makeText(this.getContext(), "connection error", Toast.LENGTH_LONG).show();
            }
        }
    });

    viewModel.getSR167TollRateItems().observe(this, tollRateGroups -> {
        if (tollRateGroups != null) {
            mEmptyView.setVisibility(View.GONE);

            Collections.sort(tollRateGroups, new SortTollGroupByLocation());
            Collections.sort(tollRateGroups, new SortTollGroupByDirection());

            tollGroups = new ArrayList<>(tollRateGroups);

            directionRadioGroup.getCheckedRadioButtonId();
            RadioButton selectedDirection = directionRadioGroup
                    .findViewById(directionRadioGroup.getCheckedRadioButtonId());

            mAdapter.setData(filterTollsForDirection(String.valueOf(selectedDirection.getText().charAt(0))));
        }
    });

    viewModel.getTravelTimesForETLFor("167").observe(this, travelTimes -> {

        TextView travelTimeView = root.findViewById(R.id.travel_time_text);

        if (travelTimes.size() > 0) {
            travelTimeView.setVisibility(View.VISIBLE);

            this.travelTimes = new ArrayList<>(travelTimes);

            travelTimeView.setText(getTravelTimeStringForDirection(radioGroupDirectionIndex == 0 ? "N" : "S"));
        } else {

            travelTimeView.setVisibility(View.GONE);
        }
    });

    timer = new Timer();
    timer.schedule(new SR167TollRatesFragment.RatesTimerTask(), 0, 60000); // Schedule rates to update every 60 seconds

    return root;
}

From source file:gov.wa.wsdot.android.wsdot.ui.tollrates.I405TollRatesFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_dynamic_toll_rates, null);

    mRecyclerView = root.findViewById(R.id.my_recycler_view);
    mRecyclerView.setHasFixedSize(true);
    mLayoutManager = new LinearLayoutManager(getActivity());
    mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mAdapter = new I405TollRatesItemAdapter(getActivity());
    mRecyclerView.setAdapter(mAdapter);//from   ww  w .j  av  a2 s.  c  o m

    mRecyclerView.addItemDecoration(new SimpleDividerItemDecoration(getActivity()));

    mRecyclerView.setPadding(0, 0, 0, 120);

    addDisclaimerView(root);

    directionRadioGroup = root.findViewById(R.id.segment_control);

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
    radioGroupDirectionIndex = sharedPref.getInt(getString(R.string.toll_rates_405_travel_direction_key), 0);

    if (radioGroupDirectionIndex == 0) {
        RadioButton leftSegment = root.findViewById(R.id.radio_left);
        leftSegment.setChecked(true);
    } else {
        RadioButton rightSegment = root.findViewById(R.id.radio_right);
        rightSegment.setChecked(true);
    }

    directionRadioGroup.setOnCheckedChangeListener((group, checkedId) -> {

        RadioButton selectedDirection = directionRadioGroup.findViewById(checkedId);

        mAdapter.setData(filterTollsForDirection(String.valueOf(selectedDirection.getText().charAt(0))));

        mLayoutManager.scrollToPositionWithOffset(0, 0);
        SharedPreferences sharedPref1 = PreferenceManager.getDefaultSharedPreferences(getContext());
        SharedPreferences.Editor editor = sharedPref1.edit();

        radioGroupDirectionIndex = directionRadioGroup.indexOfChild(selectedDirection);

        TextView travelTimeView = root.findViewById(R.id.travel_time_text);
        travelTimeView.setText(getTravelTimeStringForDirection(radioGroupDirectionIndex == 0 ? "N" : "S"));

        editor.putInt(getString(R.string.toll_rates_405_travel_direction_key), radioGroupDirectionIndex);

        editor.apply();

    });

    // For some reason, if we omit this, NoSaveStateFrameLayout thinks we are
    // FILL_PARENT / WRAP_CONTENT, making the progress bar stick to the top of the activity.
    root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    swipeRefreshLayout = root.findViewById(R.id.swipe_container);
    swipeRefreshLayout.setOnRefreshListener(this);
    swipeRefreshLayout.setColorSchemeResources(R.color.holo_blue_bright, R.color.holo_green_light,
            R.color.holo_orange_light, R.color.holo_red_light);

    mEmptyView = root.findViewById(R.id.empty_list_view);

    TextView header_link = root.findViewById(R.id.header_text);

    // create spannable string for underline
    SpannableString content = new SpannableString(
            getActivity().getResources().getString(R.string.i405_info_link));
    content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
    header_link.setText(content);

    header_link.setTextColor(getResources().getColor(R.color.primary_default));
    header_link.setOnClickListener(v -> {
        Intent intent = new Intent();
        // GA tracker
        mTracker = ((WsdotApplication) getActivity().getApplication()).getDefaultTracker();
        mTracker.setScreenName("/Toll Rates/Learn about I-405");
        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
        intent.setAction(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("https://www.wsdot.wa.gov/Tolling/405/rates.htm"));
        startActivity(intent);
    });

    viewModel = ViewModelProviders.of(this, viewModelFactory).get(TollRatesViewModel.class);

    viewModel.getResourceStatus().observe(this, resourceStatus -> {
        if (resourceStatus != null) {
            switch (resourceStatus.status) {
            case LOADING:
                swipeRefreshLayout.setRefreshing(true);
                break;
            case SUCCESS:
                swipeRefreshLayout.setRefreshing(false);
                break;
            case ERROR:
                swipeRefreshLayout.setRefreshing(false);
                Toast.makeText(this.getContext(), "connection error", Toast.LENGTH_LONG).show();
            }
        }
    });

    viewModel.getTravelTimesStatus().observe(this, resourceStatus -> {
        if (resourceStatus != null) {
            switch (resourceStatus.status) {
            case LOADING:
                break;
            case SUCCESS:
                root.findViewById(R.id.travel_time_text).setVisibility(View.VISIBLE);
                break;
            case ERROR:
                root.findViewById(R.id.travel_time_text).setVisibility(View.GONE);
            }
        }
    });

    viewModel.getI405TollRateItems().observe(this, tollRateGroups -> {
        if (tollRateGroups != null) {

            mEmptyView.setVisibility(View.GONE);

            Collections.sort(tollRateGroups, new SortTollGroupByLocation());
            Collections.sort(tollRateGroups, new SortTollGroupByDirection());

            tollGroups = new ArrayList<>(tollRateGroups);

            directionRadioGroup.getCheckedRadioButtonId();
            RadioButton selectedDirection = directionRadioGroup
                    .findViewById(directionRadioGroup.getCheckedRadioButtonId());

            mAdapter.setData(filterTollsForDirection(String.valueOf(selectedDirection.getText().charAt(0))));
        }
    });

    viewModel.getTravelTimesForETLFor("405").observe(this, travelTimes -> {

        TextView travelTimeView = root.findViewById(R.id.travel_time_text);

        if (travelTimes.size() > 0) {
            travelTimeView.setVisibility(View.VISIBLE);

            this.travelTimes = new ArrayList<>(travelTimes);

            travelTimeView.setText(getTravelTimeStringForDirection(radioGroupDirectionIndex == 0 ? "N" : "S"));
        } else {
            travelTimeView.setVisibility(View.GONE);
        }
    });

    timer = new Timer();
    timer.schedule(new RatesTimerTask(), 0, 60000); // Schedule rates to update every 60 seconds

    return root;
}

From source file:group.pals.android.lib.ui.filechooser.FragmentFiles.java

/**
 * Setup:/*from   w ww .  ja v a  2s.c o m*/
 * <p/>
 * <ul>
 * <li>button Cancel;</li>
 * <li>text field "save as" filename;</li>
 * <li>button OK;</li>
 * </ul>
 */
private void setupFooter() {
    /*
     * By default, view group footer and all its child views are hidden.
     */

    ViewGroup viewGroupFooterContainer = (ViewGroup) getView()
            .findViewById(R.id.afc_viewgroup_footer_container);
    ViewGroup viewGroupFooter = (ViewGroup) getView().findViewById(R.id.afc_viewgroup_footer);

    if (mIsSaveDialog) {
        viewGroupFooterContainer.setVisibility(View.VISIBLE);
        viewGroupFooter.setVisibility(View.VISIBLE);

        mTextSaveas.setVisibility(View.VISIBLE);
        mTextSaveas.setText(getArguments().getString(FileChooserActivity.EXTRA_DEFAULT_FILENAME));
        mTextSaveas.setOnEditorActionListener(new TextView.OnEditorActionListener() {

            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_DONE) {
                    Ui.showSoftKeyboard(v, false);
                    mBtnOk.performClick();
                    return true;
                }
                return false;
            }// onEditorAction()
        });
        mTextSaveas.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                /*
                 * Do nothing.
                 */
            }// onTextChanged()

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                /*
                 * Do nothing.
                 */
            }// beforeTextChanged()

            @Override
            public void afterTextChanged(Editable s) {
                /*
                 * If the user taps a file, the tag is set to that file's
                 * URI. But if the user types the file name, we remove the
                 * tag.
                 */
                mTextSaveas.setTag(null);
            }// afterTextChanged()
        });

        mBtnOk.setVisibility(View.VISIBLE);
        mBtnOk.setOnClickListener(mBtnOk_SaveDialog_OnClickListener);
        mBtnOk.setBackgroundResource(Ui.resolveAttribute(getActivity(), R.attr.afc_selector_button_ok_saveas));

        int size = getResources().getDimensionPixelSize(R.dimen.afc_button_ok_saveas_size);
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mBtnOk.getLayoutParams();
        lp.width = size;
        lp.height = size;
        mBtnOk.setLayoutParams(lp);
    } // this is in save mode
    else {
        if (mIsMultiSelection) {
            viewGroupFooterContainer.setVisibility(View.VISIBLE);
            viewGroupFooter.setVisibility(View.VISIBLE);

            ViewGroup.LayoutParams lp = viewGroupFooter.getLayoutParams();
            lp.width = ViewGroup.LayoutParams.WRAP_CONTENT;
            viewGroupFooter.setLayoutParams(lp);

            mBtnOk.setMinWidth(getResources().getDimensionPixelSize(R.dimen.afc_single_button_min_width));
            mBtnOk.setText(android.R.string.ok);
            mBtnOk.setVisibility(View.VISIBLE);
            mBtnOk.setOnClickListener(mBtnOk_OpenDialog_OnClickListener);
        }
    } // this is in open mode
}

From source file:com.haibison.android.anhuu.FragmentFiles.java

/**
 * Setup://from w w  w  .jav a  2 s . c om
 * <p/>
 * <ul>
 * <li>button Cancel;</li>
 * <li>text field "save as" filename;</li>
 * <li>button OK;</li>
 * </ul>
 */
private void setupFooter() {
    /*
     * By default, view group footer and all its child views are hidden.
     */

    ViewGroup viewGroupFooterContainer = (ViewGroup) getView()
            .findViewById(R.id.anhuu_f5be488d_viewgroup_footer_container);
    ViewGroup viewGroupFooter = (ViewGroup) getView().findViewById(R.id.anhuu_f5be488d_viewgroup_footer);

    if (mIsSaveDialog) {
        viewGroupFooterContainer.setVisibility(View.VISIBLE);
        viewGroupFooter.setVisibility(View.VISIBLE);

        mTextSaveas.setVisibility(View.VISIBLE);
        mTextSaveas.setText(getArguments().getString(FileChooserActivity.EXTRA_DEFAULT_FILENAME));
        mTextSaveas.setOnEditorActionListener(new TextView.OnEditorActionListener() {

            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_DONE) {
                    UI.showSoftKeyboard(v, false);
                    mBtnOk.performClick();
                    return true;
                }
                return false;
            }// onEditorAction()
        });
        mTextSaveas.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                /*
                 * Do nothing.
                 */
            }// onTextChanged()

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                /*
                 * Do nothing.
                 */
            }// beforeTextChanged()

            @Override
            public void afterTextChanged(Editable s) {
                /*
                 * If the user taps a file, the tag is set to that file's
                 * URI. But if the user types the file name, we remove the
                 * tag.
                 */
                mTextSaveas.setTag(null);
            }// afterTextChanged()
        });

        mBtnOk.setVisibility(View.VISIBLE);
        mBtnOk.setOnClickListener(mBtnOk_SaveDialog_OnClickListener);
        mBtnOk.setBackgroundResource(
                UI.resolveAttribute(getActivity(), R.attr.anhuu_f5be488d_selector_button_ok_saveas));

        int size = getResources().getDimensionPixelSize(R.dimen.anhuu_f5be488d_button_ok_saveas_size);
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mBtnOk.getLayoutParams();
        lp.width = size;
        lp.height = size;
        mBtnOk.setLayoutParams(lp);
    } // this is in save mode
    else {
        if (mIsMultiSelection) {
            viewGroupFooterContainer.setVisibility(View.VISIBLE);
            viewGroupFooter.setVisibility(View.VISIBLE);

            ViewGroup.LayoutParams lp = viewGroupFooter.getLayoutParams();
            lp.width = ViewGroup.LayoutParams.WRAP_CONTENT;
            viewGroupFooter.setLayoutParams(lp);

            mBtnOk.setMinWidth(
                    getResources().getDimensionPixelSize(R.dimen.anhuu_f5be488d_single_button_min_width));
            mBtnOk.setText(android.R.string.ok);
            mBtnOk.setVisibility(View.VISIBLE);
            mBtnOk.setOnClickListener(mBtnOk_OpenDialog_OnClickListener);
        }
    } // this is in open mode
}

From source file:gov.wa.wsdot.android.wsdot.ui.home.FavoritesFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_favorites, null);

    // Check preferences and set defaults if none set
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext());
    orderedViewTypes[0] = settings.getInt("KEY_FIRST_FAVORITES_SECTION", MY_ROUTE_VIEWTYPE);
    orderedViewTypes[1] = settings.getInt("KEY_SECOND_FAVORITES_SECTION", CAMERAS_VIEWTYPE);
    orderedViewTypes[2] = settings.getInt("KEY_THIRD_FAVORITES_SECTION", FERRIES_SCHEDULES_VIEWTYPE);
    orderedViewTypes[3] = settings.getInt("KEY_FOURTH_FAVORITES_SECTION", MOUNTAIN_PASSES_VIEWTYPE);
    orderedViewTypes[4] = settings.getInt("KEY_FIFTH_FAVORITES_SECTION", TRAVEL_TIMES_VIEWTYPE);
    orderedViewTypes[5] = settings.getInt("KEY_SIXTH_FAVORITES_SECTION", LOCATION_VIEWTYPE);
    orderedViewTypes[6] = settings.getInt("KEY_SEVENTH_FAVORITES_SECTION", TOLL_RATE_VIEWTYPE);

    mRecyclerView = root.findViewById(R.id.my_recycler_view);
    mRecyclerView.setHasFixedSize(true);
    mLayoutManager = new LinearLayoutManager(getActivity());
    mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mFavoritesAdapter = new FavItemAdapter();

    mRecyclerView.setAdapter(mFavoritesAdapter);

    // Add swipe dismiss to favorites list items.
    ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0,
            ItemTouchHelper.LEFT) {// w w w  .  j  a  v a  2  s  .  c  o  m

        @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
                RecyclerView.ViewHolder target) {
            return false;
        }

        @Override
        public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
            if (viewHolder instanceof HeaderViewHolder)
                return 0;
            return super.getSwipeDirs(recyclerView, viewHolder);
        }

        @Override
        public void onSwiped(final RecyclerView.ViewHolder holder, int swipeDir) {

            final String item_id;
            final int viewType = mFavoritesAdapter.getItemViewType(holder.getAdapterPosition());

            //Keeps holders data for undo
            holder.setIsRecyclable(false);

            //get the camera id or tag for the item being removed.
            switch (viewType) {
            case CAMERAS_VIEWTYPE:
                CameraEntity camera = (CameraEntity) mFavoritesAdapter.getItem(holder.getAdapterPosition());
                item_id = String.valueOf(camera.getCameraId());
                break;
            case FERRIES_SCHEDULES_VIEWTYPE:
                FerryScheduleEntity schedule = (FerryScheduleEntity) mFavoritesAdapter
                        .getItem(holder.getAdapterPosition());
                item_id = String.valueOf(schedule.getFerryScheduleId());
                break;
            case TRAVEL_TIMES_VIEWTYPE:
                TravelTimeGroup group = (TravelTimeGroup) mFavoritesAdapter
                        .getItem(holder.getAdapterPosition());
                item_id = String.valueOf(group.trip.getTitle());
                break;
            case MOUNTAIN_PASSES_VIEWTYPE:
                MountainPassEntity pass = (MountainPassEntity) mFavoritesAdapter
                        .getItem(holder.getAdapterPosition());
                item_id = String.valueOf(pass.getPassId());
                break;
            case LOCATION_VIEWTYPE:
                MapLocationEntity location = (MapLocationEntity) mFavoritesAdapter
                        .getItem(holder.getAdapterPosition());
                item_id = String.valueOf(location.getLocationId());
                break;
            case MY_ROUTE_VIEWTYPE:
                MyRouteEntity myRoute = (MyRouteEntity) mFavoritesAdapter.getItem(holder.getAdapterPosition());
                item_id = String.valueOf(myRoute.getMyRouteId());
                break;
            case TOLL_RATE_VIEWTYPE:
                TollRateGroup tollRateGroup = (TollRateGroup) mFavoritesAdapter
                        .getItem((holder.getAdapterPosition()));
                item_id = String.valueOf(tollRateGroup.tollRateSign.getId());
                break;
            default:
                item_id = null;
            }

            mFavoritesAdapter.remove(item_id, viewType);

            // Display snack bar with undo button
            final Snackbar snackbar = Snackbar.make(mRecyclerView, R.string.remove_favorite,
                    Snackbar.LENGTH_LONG);

            snackbar.setAction("UNDO", view -> mFavoritesAdapter.undo(item_id, viewType, holder));
            snackbar.show();
        }
    };

    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
    itemTouchHelper.attachToRecyclerView(mRecyclerView);

    // For some reason, if we omit this, NoSaveStateFrameLayout thinks we are
    // FILL_PARENT / WRAP_CONTENT, making the progress bar stick to the top of the activity.
    root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    swipeRefreshLayout = root.findViewById(R.id.swipe_container);
    swipeRefreshLayout.setOnRefreshListener(this);
    swipeRefreshLayout.setColorSchemeResources(R.color.holo_blue_bright, R.color.holo_green_light,
            R.color.holo_orange_light, R.color.holo_red_light);

    mEmptyView = root.findViewById(R.id.empty_list_view);

    viewModel = ViewModelProviders.of(this, viewModelFactory).get(FavoritesViewModel.class);

    viewModel.getFavoriteCameras().observe(this, cameras -> {
        if (cameras != null) {
            if (cameras.size() > 0) {
                mEmptyView.setVisibility(View.GONE);
            }
            mFavoritesAdapter.setCameras(cameras);
        }
    });

    viewModel.getFavoriteFerrySchedules().observe(this, ferrySchedules -> {
        if (ferrySchedules != null) {
            if (ferrySchedules.size() > 0) {
                mEmptyView.setVisibility(View.GONE);
            }
            mFavoritesAdapter.setFerrySchedules(ferrySchedules);
        }
    });

    viewModel.getFavoriteTravelTimes().observe(this, travelTimeGroups -> {
        if (travelTimeGroups != null) {
            if (travelTimeGroups.size() > 0) {
                mEmptyView.setVisibility(View.GONE);
            }
            mFavoritesAdapter.setTravelTimeGroups(travelTimeGroups);
        }
    });

    viewModel.getFavoritePasses().observe(this, passes -> {
        if (passes != null) {
            if (passes.size() > 0) {
                mEmptyView.setVisibility(View.GONE);
            }
            mFavoritesAdapter.setPasses(passes);
        }
    });

    viewModel.getFavoriteMyRoutes().observe(this, myRoutes -> {
        if (myRoutes != null) {
            if (myRoutes.size() > 0) {
                mEmptyView.setVisibility(View.GONE);
            }
            mFavoritesAdapter.setMyRoutes(myRoutes);
        }
    });

    viewModel.getMapLocations().observe(this, mapLocations -> {
        if (mapLocations != null) {
            if (mapLocations.size() > 0) {
                mEmptyView.setVisibility(View.GONE);
            }
            mFavoritesAdapter.setMapLocations(mapLocations);
        }
    });

    viewModel.getFavoriteTollRates().observe(this, tollRateGroups -> {
        if (tollRateGroups != null) {

            if (tollRateGroups.size() > 0) {
                mEmptyView.setVisibility(View.GONE);
            }

            Collections.sort(tollRateGroups, new SortTollGroupByLocation());
            Collections.sort(tollRateGroups, new SortTollGroupByDirection());
            Collections.sort(tollRateGroups, new SortTollGroupByStateRoute());

            mFavoritesAdapter.setTollRates(tollRateGroups);
        }
    });

    viewModel.getFavoritesLoadingTasksCount().observe(this, numTasks -> {
        if (numTasks != null) {

            if (numTasks == 0) {
                swipeRefreshLayout.setRefreshing(false);
            } else if (numTasks < 0) {
                Log.e(TAG, "numTasks in invalid state");
            } else {
                swipeRefreshLayout.setRefreshing(true);
            }
        }
    });

    return root;
}