Example usage for android.widget LinearLayout requestLayout

List of usage examples for android.widget LinearLayout requestLayout

Introduction

In this page you can find the example usage for android.widget LinearLayout requestLayout.

Prototype

@CallSuper
public void requestLayout() 

Source Link

Document

Call this when something has changed which has invalidated the layout of this view.

Usage

From source file:de.spiritcroc.modular_remote.Util.java

public static void resizeLayoutWidth(View containerView, LinearLayout layout, double size,
        int valueForNegativeSize) {
    if (size > 0) {
        layout.getLayoutParams().width = getWidthFromBlockUnits(containerView, size, false);
    } else {//  w w  w  .ja  v  a  2 s  .c  o  m
        layout.getLayoutParams().width = valueForNegativeSize;
    }
    layout.requestLayout();
}

From source file:de.spiritcroc.modular_remote.Util.java

public static void resizeLayoutHeight(View containerView, LinearLayout layout, double size,
        int valueForNegativeSize) {
    if (size > 0) {
        layout.getLayoutParams().height = getHeightFromBlockUnits(containerView, size, false);
    } else {/*  w w w  .  j  av a  2  s.  c  om*/
        layout.getLayoutParams().height = valueForNegativeSize;
    }
    layout.requestLayout();
}

From source file:com.example.angelina.travelapp.map.MapActivity.java

/**
 * Display the specific directions for the segment of the route
 * the user has clicked on./* w ww  .j  a va2 s.  c o  m*/
 * @param position An integer representing the index in the
 *                 list of segment directions.
 */
public final void showRouteDetail(final int position) {
    // Hide the list of directions
    final LinearLayout layout = (LinearLayout) findViewById(R.id.route_directions_container);
    layout.setLayoutParams(new CoordinatorLayout.LayoutParams(0, 0));
    layout.requestLayout();

    // Restore the map, removing any route segment detail
    final MapFragment mapFragment = restoreMapAndRemoveRouteDetail();
    // Add specific route segment detail
    mapFragment.showRouteDetail(position);
}

From source file:com.example.angelina.travelapp.map.MapActivity.java

/**
 * Restore map to original size and remove
 * views associated with displaying route segments.
 * @return MapFragment - The fragment containing the map
 *//* w w w .ja  v  a 2s . c o  m*/
public final MapFragment restoreMapAndRemoveRouteDetail() {
    // Remove the route directions
    final LinearLayout layout = (LinearLayout) findViewById(R.id.route_directions_container);
    layout.setLayoutParams(new CoordinatorLayout.LayoutParams(0, 0));
    layout.requestLayout();

    // Show the map
    final FrameLayout mapLayout = (FrameLayout) findViewById(R.id.map_fragment_container);

    final CoordinatorLayout.LayoutParams layoutParams = new CoordinatorLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    mapLayout.setLayoutParams(layoutParams);
    mapLayout.requestLayout();

    final FragmentManager fm = getSupportFragmentManager();
    final MapFragment mapFragment = (MapFragment) fm.findFragmentById(R.id.map_fragment_container);
    mapFragment.removeRouteDetail();
    return mapFragment;
}

From source file:com.example.angelina.travelapp.map.MapActivity.java

/**
 * Show the list of directions/*from   w w  w.j av  a  2  s.  c o  m*/
 * @param directions List of DirectionManeuver items containing navigation directions
 */
public final void showDirections(final List<DirectionManeuver> directions) {
    final FragmentManager fm = getSupportFragmentManager();
    RouteDirectionsFragment routeDirectionsFragment = (RouteDirectionsFragment) fm
            .findFragmentById(R.id.route_directions_container);
    if (routeDirectionsFragment == null) {
        routeDirectionsFragment = RouteDirectionsFragment.newInstance();
        ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), routeDirectionsFragment,
                R.id.route_directions_container, getString(R.string.route_fragment));
    }
    // Show the fragment
    final LinearLayout layout = (LinearLayout) findViewById(R.id.route_directions_container);
    layout.setLayoutParams(new CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    layout.requestLayout();

    // Hide the map
    final FrameLayout mapLayout = (FrameLayout) findViewById(R.id.map_fragment_container);
    final CoordinatorLayout.LayoutParams layoutParams = new CoordinatorLayout.LayoutParams(0, 0);
    layoutParams.setMargins(0, 0, 0, 0);
    mapLayout.setLayoutParams(layoutParams);
    mapLayout.requestLayout();

    routeDirectionsFragment.setRoutingDirections(directions);
}

From source file:com.thalespf.library.wizardmaker.wizard.internal.WizardContainer.java

public void initWizard() {
    ActionBarSherlock mSherlock = wizardActivity.getActionBarSherlock();

    LinearLayout ll = (LinearLayout) LayoutInflater.from(wizardActivity)
            .inflate(R.layout.wizard_maker_wizard_container, null);

    shifter = ShifterFactory.createShifter(wizard.getShifterViewLocation(), controller);

    View shifterView = shifter.getShifterView(wizardActivity);

    if (wizard.getShifterViewLocation() == IWizard.VALUE__SHIFTER_VIEW_LOCATION_ABOVE) {
        mSherlock.setContentView(ll);//from   w  ww  . j  a v  a 2s .  c  o  m
        mSherlock.getActionBar().setCustomView(shifterView);
        mSherlock.getActionBar().setDisplayShowCustomEnabled(true);
    } else if (wizard.getShifterViewLocation() == IWizard.VALUE__SHIFTER_VIEW_LOCATION_BELOW) {
        ll.addView(shifterView);
        ll.requestLayout();
        mSherlock.setContentView(ll);
    }

    wizard.onCreatePages();
    reviewPage = null;

    pagerAdapter = new PagerAdapt(wizardActivity.getSupportFragmentManager());
    viewPager = (ViewPager) wizardActivity.findViewById(R.id.pager);
    viewPager.setAdapter(pagerAdapter);

    updateShifter();
    registerListeners();
}

From source file:com.todoroo.astrid.activity.TaskEditFragment.java

public static void setViewHeightBasedOnChildren(LinearLayout view) {

    int totalHeight = 0;
    int desiredWidth = MeasureSpec.makeMeasureSpec(view.getWidth(), MeasureSpec.AT_MOST);
    for (int i = 0; i < view.getChildCount(); i++) {
        View listItem = view.getChildAt(i);
        listItem.measure(desiredWidth, MeasureSpec.UNSPECIFIED);
        totalHeight += listItem.getMeasuredHeight();
    }/*from   w  w w.  j a v  a  2 s.  co  m*/

    ViewGroup.LayoutParams params = view.getLayoutParams();
    if (params == null)
        return;

    params.height = totalHeight;
    view.setLayoutParams(params);
    view.requestLayout();
}

From source file:com.esri.android.ecologicalmarineunitexplorer.MainActivity.java

/**
 * Attach display logic to bottom sheet behavior.
 */// w  ww  .j  a  va  2 s  .  c om
private void setUpBottomSheetFragment() {
    final FragmentManager fm = getSupportFragmentManager();
    BottomSheetFragment mBottomSheetFragment = (BottomSheetFragment) fm
            .findFragmentById(R.id.bottom_sheet_view);

    if (mBottomSheetFragment == null) {
        mBottomSheetFragment = BottomSheetFragment.newInstance();
        ActivityUtils.addFragmentToActivity(fm, mBottomSheetFragment, R.id.bottom_sheet_view,
                getString(R.string.fragment_summary));
        mBottomSheetPresenter = new BottomSheetPresenter(mBottomSheetFragment);
    }

    mBottomSheetBehavior = BottomSheetBehavior.from(findViewById(R.id.bottom_sheet_view));
    if (mBottomSheetBehavior != null) {
        mBottomSheetBehavior.setHideable(true);
        mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);

        mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull final View bottomSheet, final int newState) {
                invalidateOptionsMenu();

                if (newState == BottomSheetBehavior.STATE_COLLAPSED) {
                    showBottomSheetContent();
                    mFab.setVisibility(View.VISIBLE);
                    final LinearLayout layout = (LinearLayout) findViewById(R.id.horizontalLinearLayout);
                    final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
                    layoutParams.setMargins(0, 0, 0, 0);
                    layout.setLayoutParams(layoutParams);
                    layout.requestLayout();

                }
                if (newState == BottomSheetBehavior.STATE_EXPANDED) {

                    final LinearLayout layout = (LinearLayout) findViewById(R.id.horizontalLinearLayout);
                    final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
                    final int toolbarSize = findViewById(R.id.toolbar).getHeight();
                    layoutParams.setMargins(0, toolbarSize, 0, 0);
                    layout.setLayoutParams(layoutParams);
                    layout.requestLayout();
                }
                if (newState == BottomSheetBehavior.STATE_HIDDEN) {
                    final Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.chartContainer);
                    if (fragment == null) {
                        mFab.setVisibility(View.VISIBLE);
                    } else {
                        mFab.setVisibility(View.INVISIBLE);
                    }
                }
            }

            @Override
            public void onSlide(@NonNull final View bottomSheet, final float slideOffset) {

                final float scaleFactor = 1 - slideOffset;
                if (mFab != null) {
                    if (scaleFactor <= 1) {
                        mFab.setVisibility(View.VISIBLE);
                        mFab.animate().scaleX(1 - slideOffset).scaleY(1 - slideOffset).setDuration(0).start();
                    }
                    if (slideOffset == 1.00f) {
                        mFab.setVisibility(View.INVISIBLE);
                    }
                }
            }
        });
    }
}

From source file:com.mycelium.wallet.activity.modern.RecordsFragment.java

private LinearLayout createRecordViewList(int titleResource, List<Record> records, Record selectedRecord,
        boolean addButton) {
    LinearLayout outer = new LinearLayout(getActivity());
    outer.setOrientation(LinearLayout.VERTICAL);
    outer.setLayoutParams(_outerLayoutParameters);

    // Add title//from  w  ww .  jav a 2 s  .  c  o  m
    if (addButton) {
        // Add both a title and an "+" button
        LinearLayout titleLayout = new LinearLayout(getActivity());
        titleLayout.setOrientation(LinearLayout.HORIZONTAL);
        titleLayout.setLayoutParams(_innerLayoutParameters);
        titleLayout.addView(createTitle(titleResource));
        outer.addView(titleLayout);
    } else {
        outer.addView(createTitle(titleResource));
    }

    if (records.isEmpty()) {
        return outer;
    }

    LinearLayout inner = new LinearLayout(getActivity());
    inner.setOrientation(LinearLayout.VERTICAL);
    inner.setLayoutParams(_innerLayoutParameters);
    // inner.setBackgroundDrawable(getResources().getDrawable(R.drawable.btn_pitch_black_slim));
    inner.requestLayout();

    // build only once since it is relatively slow
    final Set<Address> addressSet = _mbwManager.getRecordManager().getWallet(_mbwManager.getWalletMode())
            .getAddressSet();
    // Add records
    for (Record record : records) {
        // Add separator
        inner.addView(createSeparator());

        // Add item
        boolean isSelected = record.address.equals(selectedRecord.address);
        View item = createRecord(outer, record, isSelected, addressSet);
        inner.addView(item);
    }

    if (records.size() > 0) {
        // Add separator
        inner.addView(createSeparator());
    }

    outer.addView(inner);
    return outer;
}

From source file:com.example.angelina.travelapp.map.MapFragment.java

/**
 * Populate the place detail contained// w w  w  .  jav  a 2 s .co  m
 * within the bottom sheet
 * @param place - Place item selected by user
 */
@Override
public final void showDetail(final Place place) {
    final TextView txtName = (TextView) mBottomSheet.findViewById(R.id.placeName);
    txtName.setText(place.getName());
    String address = place.getAddress();
    final String[] splitStrs = TextUtils.split(address, ",");
    if (splitStrs.length > 0) {
        address = splitStrs[0];
    }
    final TextView txtAddress = (TextView) mBottomSheet.findViewById(R.id.placeAddress);
    txtAddress.setText(address);
    final TextView txtPhone = (TextView) mBottomSheet.findViewById(R.id.placePhone);
    txtPhone.setText(place.getPhone());

    final LinearLayout linkLayout = (LinearLayout) mBottomSheet.findViewById(R.id.linkLayout);
    // Hide the link placeholder if no link is found
    if (place.getURL().isEmpty()) {
        linkLayout.setLayoutParams(new LinearLayoutCompat.LayoutParams(0, 0));
        linkLayout.requestLayout();
    } else {
        final int height = (int) (48 * Resources.getSystem().getDisplayMetrics().density);
        linkLayout.setLayoutParams(
                new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, height));
        linkLayout.requestLayout();
        final TextView txtUrl = (TextView) mBottomSheet.findViewById(R.id.placeUrl);
        txtUrl.setText(place.getURL());
    }

    final TextView txtType = (TextView) mBottomSheet.findViewById(R.id.placeType);
    txtType.setText(place.getType());

    // Assign the appropriate icon
    final Drawable d = CategoryHelper.getDrawableForPlace(place, getActivity());
    txtType.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null);
    bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);

    // Center map on selected place
    mPresenter.centerOnPlace(place);
    mShowSnackbar = false;
    centeredPlaceName = place.getName();
}