Search in sources :

Example 16 with AppBarLayout

use of android.support.design.widget.AppBarLayout in project ListenerMusicPlayer by hefuyicoder.

the class RotationFabBehavior method onLayoutChild.

@Override
public boolean onLayoutChild(CoordinatorLayout parent, FloatingActionButton child, int layoutDirection) {
    // First, let's make sure that the visibility of the FAB is consistent
    final List<View> dependencies = parent.getDependencies(child);
    for (int i = 0, count = dependencies.size(); i < count; i++) {
        final View dependency = dependencies.get(i);
        if (dependency instanceof AppBarLayout) {
            if (updateFabVisibilityForAppBarLayout(parent, (AppBarLayout) dependency, child)) {
                break;
            }
        }
    }
    // Now let the CoordinatorLayout lay out the FAB
    parent.onLayoutChild(child, layoutDirection);
    // Now offset it if needed
    offsetIfNeeded(parent, child);
    return true;
}
Also used : AppBarLayout(android.support.design.widget.AppBarLayout) View(android.view.View)

Example 17 with AppBarLayout

use of android.support.design.widget.AppBarLayout in project Reader by TheKeeperOfPie.

the class FragmentNewMessage method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_new_message, container, false);
    layoutCoordinator = (CoordinatorLayout) view.findViewById(R.id.layout_coordinator);
    layoutAppBar = (AppBarLayout) view.findViewById(R.id.layout_app_bar);
    scrollText = (NestedScrollView) view.findViewById(R.id.scroll_text);
    textAuthor = (TextView) view.findViewById(R.id.text_author);
    textAuthor.setText(getString(R.string.sending_from) + " " + controllerUser.getUser().getName());
    editTextRecipient = (EditText) view.findViewById(R.id.edit_recipient);
    editTextSubject = (EditText) view.findViewById(R.id.edit_subject);
    editTextMessage = (EditText) view.findViewById(R.id.edit_message);
    Bundle arguments = getArguments();
    editTextRecipient.setText(arguments.getString(ARG_RECIPIENT));
    editTextSubject.setText(arguments.getString(ARG_SUBJECT));
    editTextMessage.setText(arguments.getString(ARG_MESSAGE));
    toolbar = (Toolbar) view.findViewById(R.id.toolbar);
    toolbar.setTitle(getString(R.string.message));
    toolbar.setTitleTextColor(themer.getColorFilterPrimary().getColor());
    toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
    toolbar.setNavigationOnClickListener(v -> {
        UtilsInput.hideKeyboard(editTextMessage);
        mListener.onNavigationBackClick();
    });
    toolbar.getNavigationIcon().mutate().setColorFilter(themer.getColorFilterPrimary());
    setUpOptionsMenu();
    View.OnFocusChangeListener onFocusChangeListener = (v, hasFocus) -> {
        if (hasFocus) {
            AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
            behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
        }
    };
    editTextRecipient.setOnFocusChangeListener(onFocusChangeListener);
    editTextSubject.setOnFocusChangeListener(onFocusChangeListener);
    editTextMessage.setOnFocusChangeListener(onFocusChangeListener);
    editMarginDefault = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());
    editMarginWithActions = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 56, getResources().getDisplayMetrics());
    textPreview = (TextView) view.findViewById(R.id.text_preview);
    viewDivider = view.findViewById(R.id.view_divider);
    toolbarActions = (Toolbar) view.findViewById(R.id.toolbar_actions);
    toolbarActions.inflateMenu(R.menu.menu_editor_actions);
    toolbarActions.setOnMenuItemClickListener(this);
    tabLayout = (TabLayout) view.findViewById(R.id.layout_tab);
    tabLayout.setTabMode(TabLayout.MODE_FIXED);
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
    tabLayout.setTabTextColors(themer.getColorFilterTextMuted().getColor(), themer.getColorFilterPrimary().getColor());
    viewPager = (ViewPager) view.findViewById(R.id.view_pager);
    viewPager.setAdapter(new PagerAdapter() {

        @Override
        public CharSequence getPageTitle(int position) {
            switch(position) {
                case PAGE_BODY:
                    return getString(R.string.page_message);
                case PAGE_PREVIEW:
                    return getString(R.string.page_preview);
            }
            return super.getPageTitle(position);
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            return viewPager.getChildAt(position);
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
        }

        @Override
        public int getCount() {
            return viewPager.getChildCount();
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }
    });
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            if (position == PAGE_BODY && toolbarActions.getVisibility() == View.VISIBLE) {
                float translationY = positionOffset * (toolbarActions.getHeight() + viewDivider.getHeight());
                viewDivider.setTranslationY(translationY);
                toolbarActions.setTranslationY(translationY);
            }
        }

        @Override
        public void onPageSelected(int position) {
            if (position == PAGE_PREVIEW) {
                if (editTextMessage.length() == 0) {
                    textPreview.setText(R.string.empty_reply_preview);
                } else {
                    textPreview.setText(Html.fromHtml(Processor.process(editTextMessage.getText().toString())));
                }
            }
            itemHideActions.setVisible(position == PAGE_BODY);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    tabLayout.setupWithViewPager(viewPager);
    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    layoutCaptcha = (RelativeLayout) view.findViewById(R.id.layout_captcha);
    imageCaptcha = (ImageView) view.findViewById(R.id.image_captcha);
    editCaptcha = (EditText) view.findViewById(R.id.edit_captcha);
    buttonCaptchaRefresh = (ImageButton) view.findViewById(R.id.button_captcha_refresh);
    buttonCaptchaRefresh.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            loadCaptcha();
        }
    });
    reddit.needsCaptcha().subscribe(new Observer<String>() {

        @Override
        public void onCompleted() {
        }

        @Override
        public void onError(Throwable e) {
            e.printStackTrace();
        }

        @Override
        public void onNext(String response) {
            Log.d(TAG, "needsCaptcha onNext: " + response);
            if ("true".equalsIgnoreCase(response)) {
                layoutCaptcha.setVisibility(View.VISIBLE);
                loadCaptcha();
            }
        }
    });
    view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            Menu menu = toolbarActions.getMenu();
            int maxNum = (int) (view.getWidth() / TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48, getResources().getDisplayMetrics()));
            int numShown = 0;
            for (int index = 0; index < menu.size(); index++) {
                MenuItem menuItem = menu.getItem(index);
                menuItem.getIcon().setColorFilter(themer.getColorFilterIcon());
                if (numShown++ < maxNum - 1) {
                    menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
                } else {
                    menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
                }
            }
            // Toggle visibility to fix weird bug causing tabs to not be added
            tabLayout.setVisibility(View.GONE);
            tabLayout.setVisibility(View.VISIBLE);
            view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
        }
    });
    return view;
}
Also used : AppBarLayout(android.support.design.widget.AppBarLayout) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) ImageButton(android.widget.ImageButton) Bundle(android.os.Bundle) ImageView(android.widget.ImageView) ViewPager(android.support.v4.view.ViewPager) MenuItem(android.view.MenuItem) TabLayout(android.support.design.widget.TabLayout) Inject(javax.inject.Inject) Picasso(com.squareup.picasso.Picasso) JSONException(org.json.JSONException) Reddit(com.winsonchiu.reader.data.reddit.Reddit) JSONObject(org.json.JSONObject) Toast(android.widget.Toast) Menu(android.view.Menu) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) Log(android.util.Log) Processor(com.github.rjeschke.txtmark.Processor) UtilsInput(com.winsonchiu.reader.utils.UtilsInput) LayoutInflater(android.view.LayoutInflater) PagerAdapter(android.support.v4.view.PagerAdapter) TextUtils(android.text.TextUtils) Observer(rx.Observer) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) TypedValue(android.util.TypedValue) Toolbar(android.support.v7.widget.Toolbar) Html(android.text.Html) ViewTreeObserver(android.view.ViewTreeObserver) RelativeLayout(android.widget.RelativeLayout) Nullable(android.support.annotation.Nullable) Activity(android.app.Activity) EditText(android.widget.EditText) PagerAdapter(android.support.v4.view.PagerAdapter) TabLayout(android.support.design.widget.TabLayout) AppBarLayout(android.support.design.widget.AppBarLayout) Menu(android.view.Menu) ViewTreeObserver(android.view.ViewTreeObserver) Bundle(android.os.Bundle) ViewGroup(android.view.ViewGroup) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) TextView(android.widget.TextView) ViewPager(android.support.v4.view.ViewPager) JSONObject(org.json.JSONObject)

Example 18 with AppBarLayout

use of android.support.design.widget.AppBarLayout in project Reader by TheKeeperOfPie.

the class FragmentInbox method onCreateView.

@SuppressWarnings("ResourceType")
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_inbox, container, false);
    listener = new ControllerInbox.Listener() {

        @Override
        public void setPage(Page page) {
            spinnerPage.setSelection(adapterInboxPage.getPages().indexOf(page));
        }

        @Override
        public RecyclerView.Adapter getAdapter() {
            return adapterInbox;
        }

        @Override
        public void setToolbarTitle(CharSequence title) {
            toolbar.setTitle(title);
        }

        @Override
        public void setRefreshing(boolean refreshing) {
            swipeRefreshInbox.setRefreshing(refreshing);
        }

        @Override
        public void post(Runnable runnable) {
            recyclerInbox.post(runnable);
        }
    };
    layoutCoordinator = (CoordinatorLayout) view.findViewById(R.id.layout_coordinator);
    layoutAppBar = (AppBarLayout) view.findViewById(R.id.layout_app_bar);
    int styleColorBackground = AppSettings.THEME_DARK.equals(mListener.getThemeBackground()) ? R.style.MenuDark : R.style.MenuLight;
    ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(new ThemeWrapper(activity, UtilsColor.getThemeForColor(getResources(), themer.getColorPrimary(), mListener)), styleColorBackground);
    toolbar = (Toolbar) activity.getLayoutInflater().cloneInContext(contextThemeWrapper).inflate(R.layout.toolbar, layoutAppBar, false);
    layoutAppBar.addView(toolbar);
    ((AppBarLayout.LayoutParams) toolbar.getLayoutParams()).setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
    toolbar.setTitleTextColor(themer.getColorFilterPrimary().getColor());
    toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
    toolbar.getNavigationIcon().mutate().setColorFilter(themer.getColorFilterPrimary());
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mListener.openDrawer();
        }
    });
    setUpOptionsMenu();
    floatingActionButtonNewMessage = (FloatingActionButton) view.findViewById(R.id.fab_new_message);
    floatingActionButtonNewMessage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            FragmentNewMessage fragmentNewMessage = FragmentNewMessage.newInstance();
            getFragmentManager().beginTransaction().hide(FragmentInbox.this).add(R.id.frame_fragment, fragmentNewMessage, FragmentNewMessage.TAG).addToBackStack(null).commit();
        }
    });
    floatingActionButtonNewMessage.setColorFilter(themer.getColorFilterAccent());
    behaviorFloatingActionButton = new ScrollAwareFloatingActionButtonBehavior(activity, null, new ScrollAwareFloatingActionButtonBehavior.OnVisibilityChangeListener() {

        @Override
        public void onStartHideFromScroll() {
        }

        @Override
        public void onEndHideFromScroll() {
        }
    });
    ((CoordinatorLayout.LayoutParams) floatingActionButtonNewMessage.getLayoutParams()).setBehavior(behaviorFloatingActionButton);
    adapterInboxPage = new AdapterInboxPage(activity);
    spinnerPage = new AppCompatSpinner(contextThemeWrapper);
    toolbar.addView(spinnerPage);
    ((Toolbar.LayoutParams) spinnerPage.getLayoutParams()).setMarginEnd((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics()));
    spinnerPage.setAdapter(adapterInboxPage);
    spinnerPage.setSelection(adapterInboxPage.getPages().indexOf(controllerInbox.getPage()));
    spinnerPage.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            controllerInbox.setPage(adapterInboxPage.getItem(position));
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    swipeRefreshInbox = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_inbox);
    swipeRefreshInbox.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            controllerInbox.reload();
        }
    });
    linearLayoutManager = new LinearLayoutManager(activity);
    recyclerInbox = (RecyclerView) view.findViewById(R.id.recycler_inbox);
    recyclerInbox.setHasFixedSize(true);
    recyclerInbox.setItemAnimator(new DefaultItemAnimator());
    recyclerInbox.getItemAnimator().setRemoveDuration(UtilsAnimation.EXPAND_ACTION_DURATION);
    recyclerInbox.setLayoutManager(linearLayoutManager);
    recyclerInbox.addItemDecoration(new ItemDecorationDivider(activity, ItemDecorationDivider.VERTICAL_LIST));
    AdapterListener adapterListener = new AdapterListener() {

        @Override
        public void scrollAndCenter(int position, int height) {
            linearLayoutManager.scrollToPositionWithOffset(position, 0);
        }

        @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() {
            behaviorFloatingActionButton.animateOut(floatingActionButtonNewMessage);
            AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
            behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
        }

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

        @Override
        public void requestDisallowInterceptTouchEventVertical(boolean disallow) {
            recyclerInbox.requestDisallowInterceptTouchEvent(disallow);
            swipeRefreshInbox.requestDisallowInterceptTouchEvent(disallow);
        }

        @Override
        public void requestDisallowInterceptTouchEventHorizontal(boolean disallow) {
        }
    };
    AdapterCommentList.ViewHolderComment.Listener listenerComments = new AdapterCommentList.ViewHolderComment.Listener() {

        @Override
        public void onToggleComment(Comment comment) {
        }

        @Override
        public void onShowReplyEditor(Comment comment) {
        }

        @Override
        public void onEditComment(Comment comment, String text) {
        }

        @Override
        public void onSendComment(Comment comment, String text) {
        }

        @Override
        public void onMarkRead(Comment comment) {
        }

        @Override
        public void onLoadNestedComments(Comment comment) {
        }

        @Override
        public void onJumpToParent(Comment comment) {
        }

        @Override
        public void onViewProfile(Comment comment) {
        }

        @Override
        public void onCopyText(Comment comment) {
        }

        @Override
        public void onDeleteComment(Comment comment) {
        }

        @Override
        public void onReport(Comment comment) {
        }

        @Override
        public void onVoteComment(Comment comment, AdapterCommentList.ViewHolderComment viewHolderComment, Likes vote) {
        }

        @Override
        public void onSave(Comment comment) {
        }
    };
    if (adapterInbox == null) {
        adapterInbox = new AdapterInbox(controllerInbox, controllerUser, adapterListener, listenerComments, mListener.getEventListenerBase());
    }
    recyclerInbox.setAdapter(adapterInbox);
    return view;
}
Also used : ItemDecorationDivider(com.winsonchiu.reader.utils.ItemDecorationDivider) AdapterListener(com.winsonchiu.reader.adapter.AdapterListener) Page(com.winsonchiu.reader.data.Page) FragmentNewMessage(com.winsonchiu.reader.FragmentNewMessage) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) ContextThemeWrapper(android.view.ContextThemeWrapper) ThemeWrapper(com.winsonchiu.reader.theme.ThemeWrapper) AdapterCommentList(com.winsonchiu.reader.comments.AdapterCommentList) ScrollAwareFloatingActionButtonBehavior(com.winsonchiu.reader.utils.ScrollAwareFloatingActionButtonBehavior) ScrollAwareFloatingActionButtonBehavior(com.winsonchiu.reader.utils.ScrollAwareFloatingActionButtonBehavior) AppBarLayout(android.support.design.widget.AppBarLayout) Comment(com.winsonchiu.reader.data.reddit.Comment) AdapterListener(com.winsonchiu.reader.adapter.AdapterListener) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) AppCompatSpinner(android.support.v7.widget.AppCompatSpinner) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) ContextThemeWrapper(android.view.ContextThemeWrapper) AdapterView(android.widget.AdapterView) Likes(com.winsonchiu.reader.data.reddit.Likes)

Example 19 with AppBarLayout

use of android.support.design.widget.AppBarLayout in project Reader by TheKeeperOfPie.

the class FragmentHistory method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.fragment_history, container, false);
    layoutCoordinator = (CoordinatorLayout) view.findViewById(R.id.layout_coordinator);
    layoutAppBar = (AppBarLayout) view.findViewById(R.id.layout_app_bar);
    int styleColorBackground = AppSettings.THEME_DARK.equals(mListener.getThemeBackground()) ? R.style.MenuDark : R.style.MenuLight;
    ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(new ThemeWrapper(getActivity(), UtilsColor.getThemeForColor(getResources(), themer.getColorPrimary(), mListener)), styleColorBackground);
    toolbar = (Toolbar) getActivity().getLayoutInflater().cloneInContext(contextThemeWrapper).inflate(R.layout.toolbar, layoutAppBar, false);
    layoutAppBar.addView(toolbar);
    ((AppBarLayout.LayoutParams) toolbar.getLayoutParams()).setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
    if (getFragmentManager().getBackStackEntryCount() <= 1) {
        toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
        toolbar.setNavigationOnClickListener(v -> mListener.openDrawer());
    } else {
        toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
        toolbar.setNavigationOnClickListener(v -> mListener.onNavigationBackClick());
    }
    toolbar.getNavigationIcon().mutate().setColorFilter(themer.getColorFilterPrimary());
    toolbar.setTitleTextColor(themer.getColorFilterPrimary().getColor());
    toolbar.setTitle(R.string.history);
    setUpOptionsMenu();
    swipeRefreshHistory = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_history);
    swipeRefreshHistory.setOnRefreshListener(() -> controllerHistory.reload());
    AdapterLink.ViewHolderHeader.EventListener eventListenerHeader = new AdapterLink.ViewHolderHeader.EventListener() {

        @Override
        public void onClickSubmit(Reddit.PostType postType) {
        }

        @Override
        public void showSidebar() {
        }
    };
    AdapterListener adapterListener = new AdapterListener() {

        @Override
        public void requestMore() {
            controllerHistory.loadMoreLinks().observeOn(AndroidSchedulers.mainThread()).subscribe(new ObserverError<Listing>() {

                @Override
                public void onError(Throwable e) {
                    Toast.makeText(getContext(), getContext().getString(R.string.error_loading_links), Toast.LENGTH_SHORT).show();
                }
            });
        }

        @Override
        public void scrollAndCenter(int position, int height) {
            UtilsAnimation.scrollToPositionWithCentering(position, recyclerHistory, 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() {
            AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
            behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
        }

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

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

        @Override
        public void onSubmitComment(Link link, String text) {
        }

        @Override
        public void onDownloadImage(Link link) {
        }

        @Override
        public void onDownloadImage(Link link, String title, String fileName, String url) {
        }

        @Override
        public void onLoadUrl(Link link, boolean forceExternal) {
        }

        @Override
        public void onShowFullEditor(Link link) {
        }

        @Override
        public void onVote(Link link, AdapterLink.ViewHolderLink viewHolderLink, Likes vote) {
        }

        @Override
        public void onCopyText(Link link) {
        }

        @Override
        public void onEdit(Link link) {
        }

        @Override
        public void onDelete(Link link) {
        }

        @Override
        public void onReport(Link link) {
        }

        @Override
        public void onSave(Link link) {
        }

        @Override
        public void onShowComments(Link link, AdapterLink.ViewHolderLink viewHolderLink, Source source) {
        }

        @Override
        public void onShowError(String error) {
        }

        @Override
        public void onMarkNsfw(Link link) {
        }
    };
    if (adapterLinkList == null) {
        adapterLinkList = new AdapterHistoryLinkList(getActivity(), adapterListener, eventListenerHeader, listenerLink);
    }
    if (adapterLinkGrid == null) {
        adapterLinkGrid = new AdapterHistoryLinkGrid(getActivity(), adapterListener, eventListenerHeader, listenerLink);
    }
    if (AppSettings.MODE_LIST.equals(preferences.getString(AppSettings.INTERFACE_MODE, AppSettings.MODE_GRID))) {
        adapterLink = adapterLinkList;
    } else {
        adapterLink = adapterLinkGrid;
    }
    layoutManager = adapterLink.getLayoutManager();
    itemDecorationDivider = new ItemDecorationDivider(getActivity(), ItemDecorationDivider.VERTICAL_LIST);
    recyclerHistory = (RecyclerView) view.findViewById(R.id.recycler_history);
    recyclerHistory.setHasFixedSize(true);
    recyclerHistory.setItemAnimator(null);
    resetAdapter(adapterLink);
    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.4f;
        }

        @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) {
            final int position = viewHolder.getAdapterPosition();
            final Link link = controllerHistory.remove(position);
            if (snackbar != null) {
                snackbar.dismiss();
            }
            SpannableString text = new SpannableString(getString(R.string.history_entry_deleted));
            text.setSpan(new ForegroundColorSpan(themer.getColorFilterPrimary().getColor()), 0, text.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
            //noinspection ResourceType
            snackbar = Snackbar.make(recyclerHistory, text, UtilsAnimation.SNACKBAR_DURATION).setActionTextColor(themer.getColorFilterPrimary().getColor()).setAction(R.string.undo, new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    controllerHistory.add(position, link);
                    recyclerHistory.invalidate();
                }
            });
            snackbar.getView().setBackgroundColor(themer.getColorPrimary());
            snackbar.show();
        }
    });
    itemTouchHelper.attachToRecyclerView(recyclerHistory);
    if (layoutManager instanceof LinearLayoutManager) {
        recyclerHistory.setPadding(0, 0, 0, 0);
    } else {
        int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
        recyclerHistory.setPadding(padding, 0, padding, 0);
    }
    return view;
}
Also used : ItemDecorationDivider(com.winsonchiu.reader.utils.ItemDecorationDivider) AdapterLink(com.winsonchiu.reader.links.AdapterLink) AdapterListener(com.winsonchiu.reader.adapter.AdapterListener) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) SpannableString(android.text.SpannableString) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Source(com.winsonchiu.reader.comments.Source) ContextThemeWrapper(android.view.ContextThemeWrapper) ThemeWrapper(com.winsonchiu.reader.theme.ThemeWrapper) CustomItemTouchHelper(com.winsonchiu.reader.utils.CustomItemTouchHelper) AppBarLayout(android.support.design.widget.AppBarLayout) AdapterListener(com.winsonchiu.reader.adapter.AdapterListener) ForegroundColorSpan(android.text.style.ForegroundColorSpan) ViewGroup(android.view.ViewGroup) SearchView(android.support.v7.widget.SearchView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) SpannableString(android.text.SpannableString) ContextThemeWrapper(android.view.ContextThemeWrapper) Listing(com.winsonchiu.reader.data.reddit.Listing) RecyclerView(android.support.v7.widget.RecyclerView) Likes(com.winsonchiu.reader.data.reddit.Likes) AdapterLink(com.winsonchiu.reader.links.AdapterLink) Link(com.winsonchiu.reader.data.reddit.Link)

Example 20 with AppBarLayout

use of android.support.design.widget.AppBarLayout in project PocketHub by pockethub.

the class CreateGistActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gist_create);
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    descriptionText = finder.find(R.id.et_gist_description);
    nameText = finder.find(R.id.et_gist_name);
    contentText = finder.find(R.id.et_gist_content);
    publicCheckBox = finder.find(R.id.cb_public);
    final AppBarLayout appBarLayout = finder.find(R.id.appbar);
    // Fully expand the AppBar if something in it gets focus
    View.OnFocusChangeListener expandAppBarOnFocusChangeListener = new View.OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                appBarLayout.setExpanded(true);
            }
        }
    };
    nameText.setOnFocusChangeListener(expandAppBarOnFocusChangeListener);
    descriptionText.setOnFocusChangeListener(expandAppBarOnFocusChangeListener);
    publicCheckBox.setOnFocusChangeListener(expandAppBarOnFocusChangeListener);
    // Fully expand the AppBar if something in it changes its value
    TextWatcher expandAppBarTextWatcher = new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            appBarLayout.setExpanded(true);
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            appBarLayout.setExpanded(true);
        }

        @Override
        public void afterTextChanged(Editable s) {
            appBarLayout.setExpanded(true);
        }
    };
    nameText.addTextChangedListener(expandAppBarTextWatcher);
    descriptionText.addTextChangedListener(expandAppBarTextWatcher);
    publicCheckBox.addTextChangedListener(expandAppBarTextWatcher);
    publicCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            appBarLayout.setExpanded(true);
        }
    });
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    String text = ShareUtils.getBody(getIntent());
    if (!TextUtils.isEmpty(text)) {
        contentText.setText(text);
    }
    String subject = ShareUtils.getSubject(getIntent());
    if (!TextUtils.isEmpty(subject)) {
        descriptionText.setText(subject);
    }
    contentText.addTextChangedListener(new TextWatcherAdapter() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            updateCreateMenu(s);
        }
    });
    updateCreateMenu();
}
Also used : TextWatcherAdapter(com.github.pockethub.android.ui.TextWatcherAdapter) View(android.view.View) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) AppBarLayout(android.support.design.widget.AppBarLayout) CompoundButton(android.widget.CompoundButton) ActionBar(android.support.v7.app.ActionBar)

Aggregations

AppBarLayout (android.support.design.widget.AppBarLayout)27 View (android.view.View)15 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)11 RecyclerView (android.support.v7.widget.RecyclerView)7 Intent (android.content.Intent)6 ViewGroup (android.view.ViewGroup)6 ImageView (android.widget.ImageView)6 TabLayout (android.support.design.widget.TabLayout)5 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)5 Toolbar (android.support.v7.widget.Toolbar)5 TextView (android.widget.TextView)5 CollapsingToolbarLayout (android.support.design.widget.CollapsingToolbarLayout)4 ViewPager (android.support.v4.view.ViewPager)4 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)4 PagerAdapter (android.support.v4.view.PagerAdapter)3 NestedScrollView (android.support.v4.widget.NestedScrollView)3 ActionBar (android.support.v7.app.ActionBar)3 ViewParent (android.view.ViewParent)3 Activity (android.app.Activity)2 Bundle (android.os.Bundle)2