Java Code Examples for android.support.design.widget.CoordinatorLayout#findViewById()

The following examples show how to use android.support.design.widget.CoordinatorLayout#findViewById() . 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: CircleImageInUsercBehavior.java    From ToDoList with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化数据
 * @param parent
 * @param child
 * @param dependency
 */
private void init(CoordinatorLayout parent, CircleImageView child, View dependency) {
    if (mStartAvatarY == 0) {
        mStartAvatarY = child.getY();
    }
    if (mStartDependencyY == 0) {
        mStartDependencyY = dependency.getY();
    }
    if (mStartAvatarX == 0) {
        mStartAvatarX = child.getX();
    }

    if (mAvatarMaxHeight == 0) {
        mAvatarMaxHeight = child.getHeight();
    }
    if (mToolBarHeight == 0) {
        Toolbar toolbar = (Toolbar) parent.findViewById(R.id.user_toolbar);
        mToolBarHeight = toolbar.getHeight();
    }
}
 
Example 2
Source File: TabFragment.java    From ForPDA with GNU General Public License v3.0 5 votes vote down vote up
@CallSuper
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.fragment_base, container, false);
    //Осторожно! Чувствительно к структуре разметки! (по идеи так должно работать чуть быстрее)
    fragmentContainer = (RelativeLayout) findViewById(R.id.fragment_container);
    coordinatorLayout = (CoordinatorLayout) fragmentContainer.findViewById(R.id.coordinator_layout);
    appBarLayout = (AppBarLayout) coordinatorLayout.findViewById(R.id.appbar_layout);
    toolbarLayout = (CollapsingToolbarLayout) appBarLayout.findViewById(R.id.toolbar_layout);
    toolbarBackground = (ImageView) toolbarLayout.findViewById(R.id.toolbar_image_background);
    toolbar = (Toolbar) toolbarLayout.findViewById(R.id.toolbar);
    toolbarImageView = (ImageView) toolbar.findViewById(R.id.toolbar_image_icon);
    toolbarTitleView = (TextView) toolbar.findViewById(R.id.toolbar_title);
    toolbarSubtitleView = (TextView) toolbar.findViewById(R.id.toolbar_subtitle);
    toolbarProgress = (ProgressBar) toolbar.findViewById(R.id.toolbar_progress);
    titlesWrapper = (LinearLayout) toolbar.findViewById(R.id.toolbar_titles_wrapper);
    toolbarSpinner = (Spinner) toolbar.findViewById(R.id.toolbar_spinner);
    notifyDot = findViewById(R.id.notify_dot);
    fragmentContent = (ViewGroup) coordinatorLayout.findViewById(R.id.fragment_content);
    additionalContent = (ViewGroup) coordinatorLayout.findViewById(R.id.additional_content);
    contentProgress = (ProgressBar) additionalContent.findViewById(R.id.content_progress);
    noNetwork = (LinearLayout) coordinatorLayout.findViewById(R.id.no_network);
    //// TODO: 20.03.17 удалить и юзать только там, где нужно
    fab = (FloatingActionButton) coordinatorLayout.findViewById(R.id.fab);
    contentController = new ContentController(contentProgress, additionalContent, fragmentContent);
    return view;
}
 
Example 3
Source File: FloatingActionButtonBehavior.java    From island with Apache License 2.0 5 votes vote down vote up
@Override public boolean onDependentViewChanged(final CoordinatorLayout parent, final FloatingActionButton child, final View dependency) {
	// Block parent behavior for SnackBar if bottom sheet is visible
	if (dependency instanceof Snackbar.SnackbarLayout) {
		final ViewGroup.LayoutParams fab_general_params = child.getLayoutParams();
		if (fab_general_params instanceof CoordinatorLayout.LayoutParams) {
			final CoordinatorLayout.LayoutParams fab_params = ((CoordinatorLayout.LayoutParams) fab_general_params);
			final int anchor_id = fab_params.getAnchorId();
			if (anchor_id != 0) {
				final View anchor = parent.findViewById(anchor_id);
				if (anchor != null && anchor.getVisibility() == View.VISIBLE) return false;
			}
		}
	}
	return super.onDependentViewChanged(parent, child, dependency);
}
 
Example 4
Source File: RemoveViewsOnScroll.java    From zulip-android with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, View child, View target, int dx, int dy, int[] consumed) throws NullPointerException {
    //count index starts from 1 where as position starts from 0, thus difference 1
    //we have 2 loading layouts one at top and another at bottom of the messages which should be ignored
    //resulting in a overall difference of 3
    if (linearLayoutManager.findLastCompletelyVisibleItemPosition() < adapter.getItemCount() - 3) {
        if (dy > 0 && changeInYDir < 0 || dy < 0 && changeInYDir > 0) {
            child.animate().cancel();
            changeInYDir = 0;
        }

        changeInYDir += dy;
        if ((changeInYDir > toolbarHeight && child.getVisibility() == View.VISIBLE) && (!isViewHidden || isTopSnackBar(child)))
            hideView(child);
        else if (changeInYDir < 0 && (child.getVisibility() == View.GONE && !mIsShowing) || isTopSnackBar(child)) {
            if (child instanceof FloatingActionButton) {
                if (chatBox == null)
                    chatBox = coordinatorLayout.findViewById(R.id.messageBoxContainer);
                if (chatBox.getVisibility() == View.VISIBLE) {
                    return;
                }
            }
            showView(child);
        }
    }
}
 
Example 5
Source File: ScrollAwareFABBehavior.java    From SteamGifts with MIT License 4 votes vote down vote up
@Override
public void onNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
    super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);

    if (child.getTag() == null) {
        return;
    }

    // try to get the current page, if there's any.
    View view = coordinatorLayout;
    ViewPager viewPager = (ViewPager) coordinatorLayout.findViewById(R.id.viewPager);
    if (viewPager != null && viewPager.getAdapter() instanceof FragmentAdapter) {
        int currentPage = viewPager.getCurrentItem();
        FragmentAdapter pagerAdapter = (FragmentAdapter) viewPager.getAdapter();

        Fragment currentItem = pagerAdapter.getItem(currentPage);

        view = currentItem.getView();
    }

    if (view == null) {
        // We do not have a view we can immediately find.
        child.hide();
        return;
    }

    // Hide if we're over the first item
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list);
    if (recyclerView != null && recyclerView.getLayoutManager() instanceof LinearLayoutManager) {
        LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
        if (layoutManager.findFirstVisibleItemPosition() == 0) {
            child.hide();
        } else if (dyConsumed > 1 && child.getVisibility() == View.VISIBLE)
            child.hide();
        else if (dyConsumed < 1 && child.getVisibility() != View.VISIBLE)
            child.show();
    } else {
        // no recyclerview to attach to?
        child.hide();
    }
}