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;
}
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);
}
}
}
}
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;
}
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);
}
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;
}
Aggregations