Search in sources :

Example 11 with LayoutParams

use of android.support.v4.widget.DrawerLayout.LayoutParams in project FlexibleAdapter by davideas.

the class MainActivity method onNavigationItemSelected.

/* =======================================
	 * NAVIGATION DRAWER & FRAGMENT MANAGEMENT
	 * ======================================= */
/**
	 * IMPORTANT!! READ THE COMMENT FOR THE FRAGMENT REPLACE
	 */
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    hideFabSilently();
    CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) mFab.getLayoutParams();
    ScrollAwareFABBehavior fabBehavior = ((ScrollAwareFABBehavior) layoutParams.getBehavior());
    fabBehavior.setEnabled(false);
    // Handle navigation view item clicks
    int id = item.getItemId();
    if (id == R.id.nav_overall) {
        mFragment = FragmentOverall.newInstance(2);
    } else if (id == R.id.nav_selection_modes) {
        mFragment = FragmentSelectionModes.newInstance(2);
    } else if (id == R.id.nav_filter) {
        mFragment = FragmentAsyncFilter.newInstance(true);
    } else if (id == R.id.nav_animator) {
        mFragment = FragmentAnimators.newInstance();
    } else if (id == R.id.nav_endless_scrolling) {
        mFragment = FragmentEndlessScrolling.newInstance(2);
    } else if (id == R.id.nav_instagram_headers) {
        mFragment = FragmentInstagramHeaders.newInstance();
    } else if (id == R.id.nav_headers_and_sections) {
        mFragment = FragmentHeadersSections.newInstance(2);
        fabBehavior.setEnabled(true);
    } else if (id == R.id.nav_multi_level_expandable) {
        mFragment = FragmentExpandableMultiLevel.newInstance(2);
    } else if (id == R.id.nav_expandable_sections) {
        mFragment = FragmentExpandableSections.newInstance(3);
    } else if (id == R.id.nav_staggered) {
        mFragment = FragmentStaggeredLayout.newInstance(2);
    } else if (id == R.id.nav_model_holders) {
        mFragment = FragmentHolderSections.newInstance();
    } else if (id == R.id.nav_viewpager) {
        Intent intent = new Intent(this, ViewPagerActivity.class);
        ActivityOptionsCompat activityOptionsCompat = ActivityOptionsCompat.makeBasic();
        ActivityCompat.startActivity(this, intent, activityOptionsCompat.toBundle());
        // Close drawer
        mRecyclerView.post(new Runnable() {

            @Override
            public void run() {
                mDrawer.closeDrawer(GravityCompat.START);
            }
        });
        return true;
    } else if (id == R.id.nav_about) {
        MessageDialog.newInstance(R.drawable.ic_info_grey600_24dp, getString(R.string.about_title), getString(R.string.about_body, Utils.getVersionName(this), Integer.toString(Utils.getVersionCode(this)))).show(getFragmentManager(), MessageDialog.TAG);
        return true;
    } else if (id == R.id.nav_github) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("https://github.com/davideas/FlexibleAdapter"));
        startActivity(Intent.createChooser(intent, getString(R.string.intent_chooser)));
        return true;
    }
    // Insert the fragment by replacing any existing fragment
    if (mFragment != null) {
        // Highlight the selected item has been done by NavigationView
        item.setChecked(true);
        // THIS IS VERY IMPORTANT. Because you are going to inflate a new RecyclerView, its
        // Adapter will be null, therefore the following method cannot be called automatically!
        // If your StickyHeaderContainer is in the main view, you must call this method to clean
        // the previous sticky view. Alternatively you can move the <include> of StickyHeaderLayout
        // in the Fragment view.
        mAdapter.onDetachedFromRecyclerView(mRecyclerView);
        // Inflate the new Fragment with the new RecyclerView and a new Adapter
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.recycler_view_container, mFragment).commit();
        // Close drawer
        mRecyclerView.post(new Runnable() {

            @Override
            public void run() {
                mDrawer.closeDrawer(GravityCompat.START);
            }
        });
        //mToolbar.setSubtitle(item.getTitle());
        mHeaderView.bindTo(getString(R.string.app_name), item.getTitle());
        return true;
    }
    return false;
}
Also used : CoordinatorLayout(android.support.design.widget.CoordinatorLayout) FragmentManager(android.support.v4.app.FragmentManager) Intent(android.content.Intent) ScrollAwareFABBehavior(eu.davidea.utils.ScrollAwareFABBehavior) ActivityOptionsCompat(android.support.v4.app.ActivityOptionsCompat)

Example 12 with LayoutParams

use of android.support.v4.widget.DrawerLayout.LayoutParams in project Klyph by jonathangerbaud.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    /*
		 * if (KlyphSession.getSessionUserName() != null)
		 * {
		 * loggedIn = true;
		 * setTitle(KlyphSession.getSessionUserName());
		 * }
		 * else
		 * {
		 * if (KlyphFlags.IS_PRO_VERSION == true)
		 * setTitle(R.string.app_pro_name);
		 * else
		 * setTitle(R.string.app_name);
		 * }
		 */
    setTitle("");
    if (Session.getActiveSession() == null || KlyphSession.getSessionUserId() == null || (Session.getActiveSession() != null && Session.getActiveSession().isOpened() == false)) {
        getActionBar().hide();
        getFragmentManager().beginTransaction().add(R.id.main, new LoginFragment(), FRAGMENT_TAG).commit();
    }
    // notificationsFragment.setHasOptionsMenu(false);
    adContainer = (ViewGroup) findViewById(R.id.ad);
    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    drawerToggle = new ActionBarDrawerToggle(this, drawer, AttrUtil.getResourceId(this, R.attr.drawerIcon), R.string.open, R.string.close) {

        @Override
        public void onDrawerOpened(View view) {
            Log.d("MainActivity.onCreate(...).new ActionBarDrawerToggle() {...}", "onDrawerOpened: ");
            super.onDrawerOpened(view);
            Fragment fragment = getFragmentManager().findFragmentByTag(FRAGMENT_TAG);
            if (drawer.isDrawerOpen(Gravity.RIGHT)) {
                if (notificationsFragment != null) {
                    notificationsFragment.setHasOptionsMenu(true);
                    notificationsFragment.onOpenPane();
                }
                if (fragment != null)
                    fragment.setHasOptionsMenu(false);
            } else if (drawer.isDrawerOpen(Gravity.LEFT)) {
                if (notificationsFragment != null) {
                    notificationsFragment.setHasOptionsMenu(false);
                }
                if (fragment != null)
                    fragment.setHasOptionsMenu(true);
            }
            invalidateOptionsMenu();
        }

        @Override
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.RIGHT);
            if (!drawer.isDrawerOpen(Gravity.RIGHT)) {
                if (notificationsFragment != null)
                    notificationsFragment.setHasOptionsMenu(false);
                Fragment fragment = getFragmentManager().findFragmentByTag(FRAGMENT_TAG);
                if (fragment != null)
                    fragment.setHasOptionsMenu(true);
            }
            invalidateOptionsMenu();
        }
    };
    drawer.setDrawerListener(drawerToggle);
    final List<String> labels = KlyphPreferences.getLeftDrawerMenuLabels();
    classes = new ArrayList<String>(KlyphPreferences.getLeftDrawerMenuClasses());
    classes.add("com.abewy.android.apps.klyph.fragment.UserTimeline");
    navAdapter = new DrawerLayoutAdapter(getActionBar().getThemedContext(), R.layout.item_drawer_layout, labels);
    final ListView navList = (ListView) findViewById(R.id.drawer);
    // Setting drawers max width
    int maxWidth = getResources().getDimensionPixelSize(R.dimen.max_drawer_layout_width);
    int w = Math.min(KlyphDevice.getDeviceWidth(), KlyphDevice.getDeviceHeight()) - getResources().getDimensionPixelSize(R.dimen.dip_64);
    int finalWidth = Math.min(maxWidth, w);
    LayoutParams params = ((View) navList.getParent()).getLayoutParams();
    params.width = finalWidth;
    ((View) navList.getParent()).setLayoutParams(params);
    final View notificationContainer = findViewById(R.id.notifications_container);
    params = notificationContainer.getLayoutParams();
    params.width = finalWidth;
    notificationContainer.setLayoutParams(params);
    // End max width
    navList.setFadingEdgeLength(0);
    navList.setVerticalFadingEdgeEnabled(false);
    navList.setAdapter(navAdapter);
    navList.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, final int pos, long id) {
            updateContent(pos);
            drawer.closeDrawer(Gravity.LEFT);
        }
    });
    // Facebook HashKey
    if (KlyphFlags.LOG_FACEBOOK_HASH)
        FacebookUtil.logHash(this);
    // Hierarchy View Connector
    if (KlyphFlags.ENABLE_HIERACHY_VIEW_CONNECTOR)
        HierachyViewUtil.connectHierarchyView(this);
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) ActionBarDrawerToggle(android.support.v4.app.ActionBarDrawerToggle) LoginFragment(com.abewy.android.apps.klyph.fragment.LoginFragment) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) UserCoverImageView(com.abewy.android.apps.klyph.widget.coverImage.UserCoverImageView) TextView(android.widget.TextView) ListView(android.widget.ListView) ProfileImageView(com.abewy.android.apps.klyph.widget.ProfileImageView) LoginFragment(com.abewy.android.apps.klyph.fragment.LoginFragment) Fragment(android.app.Fragment) IKlyphFragment(com.abewy.android.apps.klyph.fragment.IKlyphFragment) ListView(android.widget.ListView)

Example 13 with LayoutParams

use of android.support.v4.widget.DrawerLayout.LayoutParams in project Reader by TheKeeperOfPie.

the class FragmentThreadList method onCreateView.

@SuppressWarnings("ResourceType")
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    initialize();
    view = bind(inflater.inflate(R.layout.fragment_thread_list, container, false));
    setUpToolbar();
    buttonExpandActions.setOnClickListener(v -> toggleLayoutActions());
    behaviorButtonExpandActions = new ScrollAwareFloatingActionButtonBehavior(getActivity(), null, new ScrollAwareFloatingActionButtonBehavior.OnVisibilityChangeListener() {

        @Override
        public void onStartHideFromScroll() {
            hideLayoutActions(0);
        }

        @Override
        public void onEndHideFromScroll() {
            buttonExpandActions.setImageResource(R.drawable.ic_unfold_more_white_24dp);
            buttonExpandActions.setColorFilter(themer.getColorFilterAccent());
        }
    });
    ((CoordinatorLayout.LayoutParams) buttonExpandActions.getLayoutParams()).setBehavior(behaviorButtonExpandActions);
    buttonJumpTop.setOnClickListener(v -> scrollToPositionWithOffset(0, 0));
    buttonJumpTop.setOnLongClickListener(v -> {
        Toast.makeText(getActivity(), getString(R.string.content_description_button_jump_top), Toast.LENGTH_SHORT).show();
        return false;
    });
    buttonClearViewed.setOnClickListener(v -> controllerLinks.clearViewed(historian));
    buttonClearViewed.setOnLongClickListener(v -> {
        Toast.makeText(getActivity(), getString(R.string.content_description_button_clear_viewed), Toast.LENGTH_SHORT).show();
        return false;
    });
    // Margin is included within shadow margin on pre-Lollipop, so remove all regular margin
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        ((CoordinatorLayout.LayoutParams) buttonExpandActions.getLayoutParams()).setMargins(0, 0, 0, 0);
        int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());
        LinearLayout.LayoutParams layoutParamsJumpTop = (LinearLayout.LayoutParams) buttonJumpTop.getLayoutParams();
        layoutParamsJumpTop.setMargins(0, 0, 0, 0);
        buttonJumpTop.setLayoutParams(layoutParamsJumpTop);
        LinearLayout.LayoutParams layoutParamsClearViewed = (LinearLayout.LayoutParams) buttonClearViewed.getLayoutParams();
        layoutParamsClearViewed.setMargins(0, 0, 0, 0);
        buttonClearViewed.setLayoutParams(layoutParamsClearViewed);
        RelativeLayout.LayoutParams layoutParamsActions = (RelativeLayout.LayoutParams) layoutActions.getLayoutParams();
        layoutParamsActions.setMarginStart(margin);
        layoutParamsActions.setMarginEnd(margin);
        layoutActions.setLayoutParams(layoutParamsActions);
    }
    buttonExpandActions.setColorFilter(themer.getColorFilterAccent());
    buttonJumpTop.setColorFilter(themer.getColorFilterAccent());
    buttonClearViewed.setColorFilter(themer.getColorFilterAccent());
    swipeRefreshThreadList.setOnRefreshListener(() -> {
        controllerLinks.reload();
    });
    AdapterListener adapterListener = new AdapterListener() {

        @Override
        public void requestMore() {
            controllerLinks.loadMore();
        }

        @Override
        public void scrollAndCenter(int position, int height) {
            UtilsAnimation.scrollToPositionWithCentering(position, recyclerThreadList, height, 0, 0, false);
        }

        @Override
        public void hideToolbar() {
            AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
            behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
        }

        @Override
        public void clearDecoration() {
            behaviorButtonExpandActions.animateOut(buttonExpandActions);
            AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
            behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
        }

        @Override
        public void requestDisallowInterceptTouchEventVertical(boolean disallow) {
            recyclerThreadList.requestDisallowInterceptTouchEvent(disallow);
            swipeRefreshThreadList.requestDisallowInterceptTouchEvent(disallow);
            itemTouchHelper.select(null, CustomItemTouchHelper.ACTION_STATE_IDLE);
        }

        @Override
        public void requestDisallowInterceptTouchEventHorizontal(boolean disallow) {
            itemTouchHelper.setDisallow(disallow);
        }
    };
    AdapterLink.ViewHolderLink.Listener listener = new LinksListenerBase(mListener.getEventListenerBase()) {

        @Override
        public void onVote(Link link, AdapterLink.ViewHolderLink viewHolderLink, Likes vote) {
            mListener.getEventListenerBase().onVote(link, vote).subscribe(new ObserverEmpty<Link>() {

                @Override
                public void onError(Throwable e) {
                    controllerLinks.getEventHolder().getErrors().call(LinksError.VOTE);
                }

                @Override
                public void onNext(Link link) {
                    controllerLinks.update(link);
                }
            });
        }

        @Override
        public void onDelete(Link link) {
            new AlertDialog.Builder(getContext()).setTitle(R.string.delete_post).setMessage(link.getTitle()).setPositiveButton(R.string.yes, (dialog, which) -> {
                mListener.getEventListenerBase().onDelete(link).subscribe(new ObserverEmpty<Link>() {

                    @Override
                    public void onError(Throwable e) {
                        controllerLinks.getEventHolder().getErrors().call(LinksError.DELETE);
                    }

                    @Override
                    public void onNext(Link link) {
                        controllerLinks.remove(link);
                    }
                });
            }).setNegativeButton(R.string.no, null).show();
        }

        @Override
        public void onReport(Link link) {
            // TODO: Add link title
            new AlertDialog.Builder(getContext()).setTitle(R.string.report_title).setSingleChoiceItems(Report.getDisplayReasons(getResources()), -1, (dialog, which) -> {
                reportSelected = Report.values()[which];
            }).setPositiveButton(R.string.ok, (dialog, which) -> {
                if (reportSelected == Report.OTHER) {
                    View viewDialog = LayoutInflater.from(getContext()).inflate(R.layout.dialog_text_input, null, false);
                    final EditText editText = (EditText) viewDialog.findViewById(R.id.edit_text);
                    editText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(100) });
                    new AlertDialog.Builder(getContext()).setView(viewDialog).setTitle(R.string.item_report).setPositiveButton(R.string.ok, (dialog1, which1) -> {
                        mListener.getEventListenerBase().onReport(link, editText.getText().toString()).subscribe(new ObserverError<String>() {

                            @Override
                            public void onError(Throwable e) {
                                controllerLinks.getEventHolder().getErrors().call(LinksError.REPORT);
                            }
                        });
                    }).setNegativeButton(R.string.cancel, (dialog1, which1) -> {
                        dialog1.dismiss();
                    }).show();
                } else if (reportSelected != null) {
                    mListener.getEventListenerBase().onReport(link, reportSelected.getReason()).subscribe(new ObserverError<String>() {

                        @Override
                        public void onError(Throwable e) {
                            controllerLinks.getEventHolder().getErrors().call(LinksError.REPORT);
                        }
                    });
                }
            }).setNegativeButton(R.string.cancel, null).show();
        }

        @Override
        public void onSave(Link link) {
            if (link.isSaved()) {
                mListener.getEventListenerBase().onUnsave(link).subscribe(new ObserverEmpty<Link>() {

                    @Override
                    public void onError(Throwable e) {
                        controllerLinks.getEventHolder().getErrors().call(LinksError.UNSAVE);
                    }

                    @Override
                    public void onNext(Link link) {
                        controllerLinks.update(link);
                    }
                });
            } else {
                mListener.getEventListenerBase().onSave(link).subscribe(new ObserverEmpty<Link>() {

                    @Override
                    public void onError(Throwable e) {
                        controllerLinks.getEventHolder().getErrors().call(LinksError.SAVE);
                    }

                    @Override
                    public void onNext(Link link) {
                        controllerLinks.update(link);
                    }
                });
            }
        }

        @Override
        public void onMarkNsfw(Link link) {
            if (link.isOver18()) {
                mListener.getEventListenerBase().onUnmarkNsfw(link).subscribe(new ObserverEmpty<Link>() {

                    @Override
                    public void onError(Throwable e) {
                        controllerLinks.getEventHolder().getErrors().call(LinksError.UNMARK_NSFW);
                    }

                    @Override
                    public void onNext(Link link) {
                        controllerLinks.update(link);
                    }
                });
            } else {
                mListener.getEventListenerBase().onMarkNsfw(link).subscribe(new ObserverEmpty<Link>() {

                    @Override
                    public void onError(Throwable e) {
                        controllerLinks.getEventHolder().getErrors().call(LinksError.MARK_NSFW);
                    }

                    @Override
                    public void onNext(Link link) {
                        controllerLinks.update(link);
                    }
                });
            }
        }
    };
    adapterLinkList = new AdapterLinkList(getActivity(), adapterListener, eventListenerHeader, listener);
    adapterLinkGrid = new AdapterLinkGrid(getActivity(), adapterListener, eventListenerHeader, listener);
    adapterLink = AppSettings.MODE_GRID.equals(preferences.getString(AppSettings.INTERFACE_MODE, AppSettings.MODE_GRID)) ? adapterLinkGrid : adapterLinkList;
    itemDecorationDivider = new ItemDecorationDivider(getActivity(), ItemDecorationDivider.VERTICAL_LIST);
    //        recyclerThreadList.setItemAnimator(null);
    resetAdapter(adapterLink);
    recyclerThreadList.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            switch(newState) {
                case RecyclerView.SCROLL_STATE_IDLE:
                case RecyclerView.SCROLL_STATE_DRAGGING:
                    picasso.resumeTag(AdapterLink.TAG_PICASSO);
                    break;
                case RecyclerView.SCROLL_STATE_SETTLING:
                    picasso.pauseTag(AdapterLink.TAG_PICASSO);
                    break;
            }
        }
    });
    itemTouchHelper = new CustomItemTouchHelper(new CustomItemTouchHelper.SimpleCallback(getActivity(), R.drawable.ic_visibility_off_white_24dp, ItemTouchHelper.START | ItemTouchHelper.END, ItemTouchHelper.START | ItemTouchHelper.END) {

        @Override
        public float getSwipeThreshold(RecyclerView.ViewHolder viewHolder) {
            if (layoutManager instanceof StaggeredGridLayoutManager) {
                return 1f / ((StaggeredGridLayoutManager) layoutManager).getSpanCount();
            }
            return 0.5f;
        }

        @Override
        public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
            if (viewHolder.getAdapterPosition() == 0) {
                return 0;
            }
            ViewGroup.LayoutParams layoutParams = viewHolder.itemView.getLayoutParams();
            if (layoutParams instanceof StaggeredGridLayoutManager.LayoutParams && !((StaggeredGridLayoutManager.LayoutParams) layoutParams).isFullSpan()) {
                int spanCount = layoutManager instanceof StaggeredGridLayoutManager ? ((StaggeredGridLayoutManager) layoutManager).getSpanCount() : 2;
                int spanIndex = ((StaggeredGridLayoutManager.LayoutParams) layoutParams).getSpanIndex() % spanCount;
                if (spanIndex == 0) {
                    return ItemTouchHelper.END;
                } else if (spanIndex == spanCount - 1) {
                    return ItemTouchHelper.START;
                }
            }
            return super.getSwipeDirs(recyclerView, viewHolder);
        }

        @Override
        public boolean isLongPressDragEnabled() {
            return false;
        }

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

        @Override
        public void onSwiped(final RecyclerView.ViewHolder viewHolder, int direction) {
            // Offset by 1 due to subreddit header
            Link link = controllerLinks.hideLink(viewHolder.getAdapterPosition());
            mListener.getEventListenerBase().hide(link);
            if (snackbar != null) {
                snackbar.dismiss();
            }
            SpannableString text = new SpannableString(link.isHidden() ? getString(R.string.link_hidden) : getString(R.string.link_shown));
            text.setSpan(new ForegroundColorSpan(themer.getColorFilterPrimary().getColor()), 0, text.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
            //noinspection ResourceType
            snackbar = Snackbar.make(recyclerThreadList, text, UtilsAnimation.SNACKBAR_DURATION).setActionTextColor(themer.getColorFilterPrimary().getColor()).setAction(R.string.undo, v -> {
                mListener.getEventListenerBase().hide(link);
                controllerLinks.reshowLastHiddenLink();
            });
            snackbar.getView().setBackgroundColor(themer.getColorPrimary());
            snackbar.show();
        }
    });
    itemTouchHelper.attachToRecyclerView(recyclerThreadList);
    recyclerThreadList.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {

        @Override
        public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
            //                rv.getChildViewHolder(rv.findChildViewUnder(e.getX(), e.getY()));
            return false;
        }

        @Override
        public void onTouchEvent(RecyclerView rv, MotionEvent e) {
        }

        @Override
        public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
        }
    });
    if (layoutManager instanceof LinearLayoutManager) {
        recyclerThreadList.setPadding(0, 0, 0, 0);
    } else {
        int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
        recyclerThreadList.setPadding(padding, 0, padding, 0);
    }
    textSidebar.setMovementMethod(LinkMovementMethod.getInstance());
    buttonSubscribe.setOnClickListener(v -> controllerLinks.subscribe());
    return view;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) ObserverEmpty(com.winsonchiu.reader.rx.ObserverEmpty) Historian(com.winsonchiu.reader.history.Historian) ViewPropertyAnimatorListener(android.support.v4.view.ViewPropertyAnimatorListener) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) LinkMovementMethod(android.text.method.LinkMovementMethod) UtilsAnimation(com.winsonchiu.reader.utils.UtilsAnimation) BindView(butterknife.BindView) Picasso(com.squareup.picasso.Picasso) Reddit(com.winsonchiu.reader.data.reddit.Reddit) Likes(com.winsonchiu.reader.data.reddit.Likes) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) View(android.view.View) Button(android.widget.Button) ViewCompat(android.support.v4.view.ViewCompat) ForegroundColorSpan(android.text.style.ForegroundColorSpan) Log(android.util.Log) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) ActionLog(com.winsonchiu.reader.rx.ActionLog) FloatingActionButton(android.support.design.widget.FloatingActionButton) CustomItemTouchHelper(com.winsonchiu.reader.utils.CustomItemTouchHelper) UtilsReddit(com.winsonchiu.reader.utils.UtilsReddit) ViewGroup(android.view.ViewGroup) R(com.winsonchiu.reader.R) UtilsColor(com.winsonchiu.reader.utils.UtilsColor) FragmentBase(com.winsonchiu.reader.FragmentBase) FragmentNewPost(com.winsonchiu.reader.FragmentNewPost) TextView(android.widget.TextView) RelativeLayout(android.widget.RelativeLayout) Time(com.winsonchiu.reader.data.reddit.Time) Nullable(android.support.annotation.Nullable) Snackbar(android.support.design.widget.Snackbar) InputFilter(android.text.InputFilter) User(com.winsonchiu.reader.data.reddit.User) Subscription(rx.Subscription) ObserverError(com.winsonchiu.reader.rx.ObserverError) Report(com.winsonchiu.reader.data.reddit.Report) AppBarLayout(android.support.design.widget.AppBarLayout) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) Spanned(android.text.Spanned) FastOutSlowInInterpolator(android.support.v4.view.animation.FastOutSlowInInterpolator) Subreddit(com.winsonchiu.reader.data.reddit.Subreddit) UtilsRx(com.winsonchiu.reader.utils.UtilsRx) AdapterListener(com.winsonchiu.reader.adapter.AdapterListener) AppSettings(com.winsonchiu.reader.AppSettings) MenuItem(android.view.MenuItem) GravityCompat(android.support.v4.view.GravityCompat) Inject(javax.inject.Inject) MotionEvent(android.view.MotionEvent) Toast(android.widget.Toast) Menu(android.view.Menu) Link(com.winsonchiu.reader.data.reddit.Link) ScrollAwareFloatingActionButtonBehavior(com.winsonchiu.reader.utils.ScrollAwareFloatingActionButtonBehavior) Build(android.os.Build) DrawerLayout(android.support.v4.widget.DrawerLayout) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) SpannableString(android.text.SpannableString) LayoutInflater(android.view.LayoutInflater) ControllerUser(com.winsonchiu.reader.ControllerUser) Sort(com.winsonchiu.reader.data.reddit.Sort) ItemDecorationDivider(com.winsonchiu.reader.utils.ItemDecorationDivider) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) TextUtils(android.text.TextUtils) Thing(com.winsonchiu.reader.data.reddit.Thing) FragmentSearch(com.winsonchiu.reader.search.FragmentSearch) RecyclerView(android.support.v7.widget.RecyclerView) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) Toolbar(android.support.v7.widget.Toolbar) ActivityMain(com.winsonchiu.reader.ActivityMain) FragmentListenerBase(com.winsonchiu.reader.FragmentListenerBase) Activity(android.app.Activity) UtilsTheme(com.winsonchiu.reader.utils.UtilsTheme) EditText(android.widget.EditText) ItemDecorationDivider(com.winsonchiu.reader.utils.ItemDecorationDivider) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) SpannableString(android.text.SpannableString) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ScrollAwareFloatingActionButtonBehavior(com.winsonchiu.reader.utils.ScrollAwareFloatingActionButtonBehavior) ScrollAwareFloatingActionButtonBehavior(com.winsonchiu.reader.utils.ScrollAwareFloatingActionButtonBehavior) AppBarLayout(android.support.design.widget.AppBarLayout) EditText(android.widget.EditText) InputFilter(android.text.InputFilter) ForegroundColorSpan(android.text.style.ForegroundColorSpan) SpannableString(android.text.SpannableString) RelativeLayout(android.widget.RelativeLayout) Link(com.winsonchiu.reader.data.reddit.Link) CustomItemTouchHelper(com.winsonchiu.reader.utils.CustomItemTouchHelper) AdapterListener(com.winsonchiu.reader.adapter.AdapterListener) ViewGroup(android.view.ViewGroup) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) MotionEvent(android.view.MotionEvent) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) ObserverError(com.winsonchiu.reader.rx.ObserverError) RecyclerView(android.support.v7.widget.RecyclerView) Likes(com.winsonchiu.reader.data.reddit.Likes) LinearLayout(android.widget.LinearLayout)

Example 14 with LayoutParams

use of android.support.v4.widget.DrawerLayout.LayoutParams in project vlayout by alibaba.

the class OnePlusNLayoutActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);
    mFirstText = (TextView) findViewById(R.id.first);
    mLastText = (TextView) findViewById(R.id.last);
    mCountText = (TextView) findViewById(R.id.count);
    mTotalOffsetText = (TextView) findViewById(R.id.total_offset);
    final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_view);
    findViewById(R.id.jump).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            EditText position = (EditText) findViewById(R.id.position);
            if (!TextUtils.isEmpty(position.getText())) {
                try {
                    int pos = Integer.parseInt(position.getText().toString());
                    recyclerView.scrollToPosition(pos);
                } catch (Exception e) {
                    Log.e("VlayoutActivity", e.getMessage(), e);
                }
            } else {
                recyclerView.requestLayout();
            }
        }
    });
    final VirtualLayoutManager layoutManager = new VirtualLayoutManager(this);
    recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int scrollState) {
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int i, int i2) {
            mFirstText.setText("First: " + layoutManager.findFirstVisibleItemPosition());
            mLastText.setText("Existing: " + MainViewHolder.existing + " Created: " + MainViewHolder.createdTimes);
            mCountText.setText("Count: " + recyclerView.getChildCount());
            mTotalOffsetText.setText("Total Offset: " + layoutManager.getOffsetToStart());
        }
    });
    recyclerView.setLayoutManager(layoutManager);
    // layoutManager.setReverseLayout(true);
    RecyclerView.ItemDecoration itemDecoration = new RecyclerView.ItemDecoration() {

        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            int position = ((LayoutParams) view.getLayoutParams()).getViewPosition();
            outRect.set(4, 4, 4, 4);
        }
    };
    final RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
    recyclerView.setRecycledViewPool(viewPool);
    // recyclerView.addItemDecoration(itemDecoration);
    viewPool.setMaxRecycledViews(0, 20);
    final DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager, true);
    recyclerView.setAdapter(delegateAdapter);
    List<DelegateAdapter.Adapter> adapters = new LinkedList<>();
    if (BANNER_LAYOUT) {
        adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 1) {

            @Override
            public void onViewRecycled(MainViewHolder holder) {
                if (holder.itemView instanceof ViewPager) {
                    ((ViewPager) holder.itemView).setAdapter(null);
                }
            }

            @Override
            public MainViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                if (viewType == 1)
                    return new MainViewHolder(LayoutInflater.from(OnePlusNLayoutActivity.this).inflate(R.layout.view_pager, parent, false));
                return super.onCreateViewHolder(parent, viewType);
            }

            @Override
            public int getItemViewType(int position) {
                return 1;
            }

            @Override
            protected void onBindViewHolderWithOffset(MainViewHolder holder, int position, int offsetTotal) {
            }

            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                if (holder.itemView instanceof ViewPager) {
                    ViewPager viewPager = (ViewPager) holder.itemView;
                    viewPager.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 200));
                    // from position to get adapter
                    viewPager.setAdapter(new PagerAdapter(this, viewPool));
                }
            }
        });
    }
    if (GRID_LAYOUT) {
        GridLayoutHelper layoutHelper;
        layoutHelper = new GridLayoutHelper(4);
        layoutHelper.setMargin(0, 10, 0, 10);
        layoutHelper.setHGap(3);
        layoutHelper.setAspectRatio(4f);
        adapters.add(new SubAdapter(this, layoutHelper, 8));
    }
    if (HORIZONTAL_SCROLL_LAYOUT) {
    }
    if (GRID_LAYOUT) {
        GridLayoutHelper layoutHelper;
        layoutHelper = new GridLayoutHelper(2);
        layoutHelper.setMargin(0, 10, 0, 10);
        layoutHelper.setHGap(3);
        layoutHelper.setAspectRatio(3f);
        adapters.add(new SubAdapter(this, layoutHelper, 2));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper();
        helper.setBgColor(0xff876384);
        helper.setMargin(10, 10, 10, 10);
        helper.setPadding(10, 10, 10, 10);
        adapters.add(new SubAdapter(this, helper, 3) {

            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
            //                    LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300);
            //                    layoutParams.leftMargin = 10;
            //                    layoutParams.topMargin = 10;
            //                    layoutParams.rightMargin = 10;
            //                    layoutParams.bottomMargin = 10;
            //                    holder.itemView.setLayoutParams(layoutParams);
            }
        });
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 4));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 5));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 5));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        helper.setColWeights(new float[] { 40f, 45f, 15f, 60f, 0f });
        adapters.add(new SubAdapter(this, helper, 5));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        helper.setColWeights(new float[] { 20f, 80f, 0f, 60f, 20f });
        helper.setAspectRatio(4);
        adapters.add(new SubAdapter(this, helper, 5));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 6));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        adapters.add(new SubAdapter(this, helper, 7));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xff876384);
        helper.setMargin(0, 10, 0, 10);
        helper.setColWeights(new float[] { 40f, 45f, 15f, 60f, 0f, 30f, 30f });
        adapters.add(new SubAdapter(this, helper, 7));
    }
    if (ONEN_LAYOUT) {
        OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx();
        helper.setBgColor(0xffed7612);
        //            helper.setMargin(10, 10, 10, 10);
        //            helper.setPadding(10, 10, 10, 10);
        helper.setColWeights(new float[] { 30f, 20f, 50f, 40f, 30f, 35f, 35f });
        adapters.add(new SubAdapter(this, helper, 7) {

            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
            //                    LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300);
            //                    layoutParams.leftMargin = 10;
            //                    layoutParams.topMargin = 10;
            //                    layoutParams.rightMargin = 10;
            //                    layoutParams.bottomMargin = 10;
            //                    holder.itemView.setLayoutParams(layoutParams);
            }
        });
    }
    if (STICKY_LAYOUT) {
        StickyLayoutHelper layoutHelper = new StickyLayoutHelper();
        layoutHelper.setAspectRatio(4);
        adapters.add(new SubAdapter(this, layoutHelper, 1, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100)));
    }
    if (SCROLL_FIX_LAYOUT) {
        ScrollFixLayoutHelper layoutHelper = new ScrollFixLayoutHelper(FixLayoutHelper.BOTTOM_RIGHT, 20, 20);
        layoutHelper.setShowType(ScrollFixLayoutHelper.SHOW_ON_LEAVE);
        adapters.add(new SubAdapter(this, layoutHelper, 1) {

            @Override
            public void onBindViewHolder(MainViewHolder holder, int position) {
                super.onBindViewHolder(holder, position);
                LayoutParams layoutParams = new LayoutParams(50, 50);
                holder.itemView.setLayoutParams(layoutParams);
            }
        });
    }
    if (LINEAR_LAYOUT)
        adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 100));
    delegateAdapter.setAdapters(adapters);
    final Handler mainHandler = new Handler(Looper.getMainLooper());
    trigger = new Runnable() {

        @Override
        public void run() {
            // recyclerView.scrollToPosition(22);
            // recyclerView.getAdapter().notifyDataSetChanged();
            recyclerView.requestLayout();
        // mainHandler.postDelayed(trigger, 1000);
        }
    };
    mainHandler.postDelayed(trigger, 1000);
}
Also used : ScrollFixLayoutHelper(com.alibaba.android.vlayout.layout.ScrollFixLayoutHelper) DelegateAdapter(com.alibaba.android.vlayout.DelegateAdapter) RecyclablePagerAdapter(com.alibaba.android.vlayout.RecyclablePagerAdapter) GridLayoutHelper(com.alibaba.android.vlayout.layout.GridLayoutHelper) RecyclablePagerAdapter(com.alibaba.android.vlayout.RecyclablePagerAdapter) DelegateAdapter(com.alibaba.android.vlayout.DelegateAdapter) StickyLayoutHelper(com.alibaba.android.vlayout.layout.StickyLayoutHelper) OnePlusNLayoutHelperEx(com.alibaba.android.vlayout.layout.OnePlusNLayoutHelperEx) EditText(android.widget.EditText) Rect(android.graphics.Rect) LayoutParams(com.alibaba.android.vlayout.VirtualLayoutManager.LayoutParams) LinearLayoutHelper(com.alibaba.android.vlayout.layout.LinearLayoutHelper) ViewGroup(android.view.ViewGroup) Handler(android.os.Handler) OnePlusNLayoutHelper(com.alibaba.android.vlayout.layout.OnePlusNLayoutHelper) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) ViewPager(android.support.v4.view.ViewPager) LinkedList(java.util.LinkedList) RecyclerView(android.support.v7.widget.RecyclerView) VirtualLayoutManager(com.alibaba.android.vlayout.VirtualLayoutManager)

Example 15 with LayoutParams

use of android.support.v4.widget.DrawerLayout.LayoutParams in project material-components-android by material-components.

the class CoordinatorLayout method onSaveInstanceState.

@Override
protected Parcelable onSaveInstanceState() {
    final SavedState ss = new SavedState(super.onSaveInstanceState());
    final SparseArray<Parcelable> behaviorStates = new SparseArray<>();
    for (int i = 0, count = getChildCount(); i < count; i++) {
        final View child = getChildAt(i);
        final int childId = child.getId();
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        final Behavior b = lp.getBehavior();
        if (childId != NO_ID && b != null) {
            // If the child has an ID and a Behavior, let it save some state...
            Parcelable state = b.onSaveInstanceState(this, child);
            if (state != null) {
                behaviorStates.append(childId, state);
            }
        }
    }
    ss.behaviorStates = behaviorStates;
    return ss;
}
Also used : AbsSavedState(android.support.v4.view.AbsSavedState) SparseArray(android.util.SparseArray) Parcelable(android.os.Parcelable) View(android.view.View) Paint(android.graphics.Paint)

Aggregations

View (android.view.View)11 FrameLayout (android.widget.FrameLayout)5 TextView (android.widget.TextView)5 RecyclerView (android.support.v7.widget.RecyclerView)4 LayoutParams (android.view.ViewGroup.LayoutParams)4 EditText (android.widget.EditText)4 Paint (android.graphics.Paint)3 ViewPager (android.support.v4.view.ViewPager)3 DrawerLayout (android.support.v4.widget.DrawerLayout)3 MotionEvent (android.view.MotionEvent)3 ViewGroup (android.view.ViewGroup)3 ImageView (android.widget.ImageView)3 Intent (android.content.Intent)2 Rect (android.graphics.Rect)2 Handler (android.os.Handler)2 Parcelable (android.os.Parcelable)2 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)2 FragmentManager (android.support.v4.app.FragmentManager)2 AbsSavedState (android.support.v4.view.AbsSavedState)2 GestureDetectorCompat (android.support.v4.view.GestureDetectorCompat)2