Search in sources :

Example 36 with NestedScrollView

use of android.support.v4.widget.NestedScrollView 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 37 with NestedScrollView

use of android.support.v4.widget.NestedScrollView in project smooth-app-bar-layout by henrytao-me.

the class BaseBehavior method initScrollTarget.

private void initScrollTarget(final CoordinatorLayout coordinatorLayout, final AppBarLayout child) {
    Utils.log("initScrollTarget | %b", vScrollTarget != null);
    if (vScrollTarget != null) {
        long tag = getViewTag(vScrollTarget, true);
        if (!mScrollTargets.contains(tag)) {
            mScrollTargets.add(tag);
            OnScrollListener listener = new OnScrollListener() {

                @Override
                public void onScrollChanged(View view, int x, int y, int dx, int dy, boolean accuracy) {
                    if (view == vScrollTarget) {
                        BaseBehavior.this.onScrollChanged(coordinatorLayout, child, view, y, dy, accuracy);
                    }
                }
            };
            if (vScrollTarget instanceof NestedScrollView) {
                ObservableNestedScrollView.newInstance((NestedScrollView) vScrollTarget, mOverrideOnScrollListener, listener);
            } else if (vScrollTarget instanceof RecyclerView) {
                ObservableRecyclerView.newInstance((RecyclerView) vScrollTarget, listener);
            }
        }
    }
}
Also used : OnScrollListener(me.henrytao.smoothappbarlayout.base.OnScrollListener) ObservableRecyclerView(me.henrytao.smoothappbarlayout.base.ObservableRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) ObservableNestedScrollView(me.henrytao.smoothappbarlayout.base.ObservableNestedScrollView) NestedScrollView(android.support.v4.widget.NestedScrollView) ObservableRecyclerView(me.henrytao.smoothappbarlayout.base.ObservableRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) ObservableNestedScrollView(me.henrytao.smoothappbarlayout.base.ObservableNestedScrollView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView)

Example 38 with NestedScrollView

use of android.support.v4.widget.NestedScrollView in project smooth-app-bar-layout by henrytao-me.

the class BaseBehavior method getSupportedScrollTarget.

private View getSupportedScrollTarget(View target) {
    if (target instanceof SwipeRefreshLayout && ((SwipeRefreshLayout) target).getChildCount() > 0) {
        SwipeRefreshLayout parent = (SwipeRefreshLayout) target;
        View child;
        int n = parent.getChildCount();
        for (int i = 0; i < n; i++) {
            child = parent.getChildAt(i);
            if (child instanceof NestedScrollView || child instanceof RecyclerView) {
                return child;
            }
        }
        return ((SwipeRefreshLayout) target).getChildAt(0);
    } else if (target instanceof CoordinatorLayout) {
        Stack<View> stack = new Stack<>();
        stack.add(target);
        while (stack.size() > 0) {
            View view = stack.pop();
            if (view instanceof NestedScrollView || view instanceof RecyclerView) {
                return view;
            }
            if (view instanceof ViewGroup) {
                int n = ((ViewGroup) view).getChildCount();
                for (int i = 0; i < n; i++) {
                    stack.add(((ViewGroup) view).getChildAt(i));
                }
            }
        }
    }
    return target;
}
Also used : CoordinatorLayout(android.support.design.widget.CoordinatorLayout) ViewGroup(android.view.ViewGroup) ObservableRecyclerView(me.henrytao.smoothappbarlayout.base.ObservableRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) ObservableNestedScrollView(me.henrytao.smoothappbarlayout.base.ObservableNestedScrollView) NestedScrollView(android.support.v4.widget.NestedScrollView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) ObservableRecyclerView(me.henrytao.smoothappbarlayout.base.ObservableRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) ObservableNestedScrollView(me.henrytao.smoothappbarlayout.base.ObservableNestedScrollView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) Stack(java.util.Stack)

Example 39 with NestedScrollView

use of android.support.v4.widget.NestedScrollView in project android by testpress.

the class PostActivity method displayComments.

void displayComments() {
    commentsAdapter = new CommentsListAdapter(this);
    listView.setNestedScrollingEnabled(false);
    listView.setLayoutManager(new LinearLayoutManager(this));
    listView.setAdapter(commentsAdapter);
    loadPreviousCommentsLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            loadPreviousCommentsLayout.setVisibility(View.GONE);
            getSupportLoaderManager().restartLoader(PREVIOUS_COMMENTS_LOADER_ID, null, PostActivity.this);
        }
    });
    loadNewCommentsLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            loadNewCommentsLayout.setVisibility(View.GONE);
            getSupportLoaderManager().restartLoader(NEW_COMMENTS_LOADER_ID, null, PostActivity.this);
        }
    });
    newCommentsAvailableLabel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            newCommentsAvailableLabel.setVisibility(View.GONE);
            scrollView.post(new Runnable() {

                @Override
                public void run() {
                    scrollView.fullScroll(View.FOCUS_DOWN);
                }
            });
        }
    });
    scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {

        @Override
        public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
            int scrollViewHeight = scrollView.getHeight();
            int totalScrollViewChildHeight = scrollView.getChildAt(0).getHeight();
            // Let's assume end has reached at 50 pixels before itself(on partial visible of last item)
            boolean endHasBeenReached = (scrollY + scrollViewHeight + 50) >= totalScrollViewChildHeight;
            if (endHasBeenReached) {
                newCommentsAvailableLabel.setVisibility(View.GONE);
            }
        }
    });
    imagePickerUtil = new ImagePickerUtil(activityRootLayout, this);
    commentsLayout.setVisibility(View.VISIBLE);
    getSupportLoaderManager().initLoader(PREVIOUS_COMMENTS_LOADER_ID, null, PostActivity.this);
}
Also used : LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) NestedScrollView(android.support.v4.widget.NestedScrollView) InjectView(butterknife.InjectView) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) NestedScrollView(android.support.v4.widget.NestedScrollView) RecyclerView(android.support.v7.widget.RecyclerView) SuppressLint(android.annotation.SuppressLint) ImagePickerUtil(in.testpress.testpress.util.ImagePickerUtil)

Example 40 with NestedScrollView

use of android.support.v4.widget.NestedScrollView in project underlx by underlx.

the class StationPOIFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mapLayoutReady = false;
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_station_poi, container, false);
    IntentFilter filter = new IntentFilter();
    filter.addAction(StationActivity.ACTION_MAIN_SERVICE_BOUND);
    LocalBroadcastManager bm = LocalBroadcastManager.getInstance(getContext());
    bm.registerReceiver(mBroadcastReceiver, filter);
    poisLayout = (LinearLayout) view.findViewById(R.id.pois_layout);
    poiScrollView = (NestedScrollView) view.findViewById(R.id.poi_scroll_view);
    mapView = (ScrollFixMapView) view.findViewById(R.id.map_view);
    mapView.onCreate(savedInstanceState);
    // needed to get the map to display immediately
    mapView.onResume();
    try {
        MapsInitializer.initialize(getActivity().getApplicationContext());
    } catch (Exception e) {
        e.printStackTrace();
    }
    update();
    return view;
}
Also used : IntentFilter(android.content.IntentFilter) ScrollFixMapView(im.tny.segvault.disturbances.ui.util.ScrollFixMapView) View(android.view.View) NestedScrollView(android.support.v4.widget.NestedScrollView) POIView(im.tny.segvault.disturbances.ui.widget.POIView) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager)

Aggregations

NestedScrollView (android.support.v4.widget.NestedScrollView)42 View (android.view.View)24 RecyclerView (android.support.v7.widget.RecyclerView)15 TextView (android.widget.TextView)11 ViewGroup (android.view.ViewGroup)9 AppBarLayout (android.support.design.widget.AppBarLayout)6 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)6 Toolbar (android.support.v7.widget.Toolbar)6 AbsListView (android.widget.AbsListView)6 ImageView (android.widget.ImageView)6 ScrollView (android.widget.ScrollView)6 ViewTreeObserver (android.view.ViewTreeObserver)5 SuppressLint (android.annotation.SuppressLint)4 ViewPager (android.support.v4.view.ViewPager)4 Test (org.junit.Test)4 Activity (android.app.Activity)3 Bundle (android.os.Bundle)3 TabLayout (android.support.design.widget.TabLayout)3 PagerAdapter (android.support.v4.view.PagerAdapter)3 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3