Search in sources :

Example 26 with ObservableListView

use of com.github.ksoichiro.android.observablescrollview.ObservableListView in project UltimateAndroid by cymcsg.

the class FlexibleSpaceWithImageListViewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.observable_scroll_view_activity_flexiblespacewithimagelistview);
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    mFlexibleSpaceImageHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
    mFlexibleSpaceShowFabOffset = getResources().getDimensionPixelSize(R.dimen.flexible_space_show_fab_offset);
    mActionBarSize = getActionBarSize();
    mToolbarColor = getResources().getColor(R.color.primary);
    mToolbar = findViewById(R.id.toolbar);
    if (!TOOLBAR_IS_STICKY) {
        mToolbar.setBackgroundColor(Color.TRANSPARENT);
    }
    mImageView = findViewById(R.id.image);
    mOverlayView = findViewById(R.id.overlay);
    ObservableListView listView = (ObservableListView) findViewById(R.id.list);
    listView.setScrollViewCallbacks(this);
    // Set padding view for ListView. This is the flexible space.
    View paddingView = new View(this);
    AbsListView.LayoutParams lp = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, mFlexibleSpaceImageHeight);
    paddingView.setLayoutParams(lp);
    // This is required to disable header's list selector effect
    paddingView.setClickable(true);
    listView.addHeaderView(paddingView);
    List<String> items = new ArrayList<String>();
    for (int i = 1; i <= 100; i++) {
        items.add("Item " + i);
    }
    listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items));
    mTitleView = (TextView) findViewById(R.id.title);
    mTitleView.setText(getTitle());
    setTitle(null);
    mFab = findViewById(R.id.fab);
    mFabMargin = getResources().getDimensionPixelSize(R.dimen.margin_standard);
    ViewHelper.setScaleX(mFab, 0);
    ViewHelper.setScaleY(mFab, 0);
    // mListBackgroundView makes ListView's background except header view.
    mListBackgroundView = findViewById(R.id.list_background);
    final View contentView = getWindow().getDecorView().findViewById(android.R.id.content);
    contentView.post(new Runnable() {

        @Override
        public void run() {
            // mListBackgroundView's should fill its parent vertically
            // but the height of the content view is 0 on 'onCreate'.
            // So we should get it with post().
            mListBackgroundView.getLayoutParams().height = contentView.getHeight();
        }
    });
}
Also used : ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView) ArrayList(java.util.ArrayList) AbsListView(android.widget.AbsListView) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) View(android.view.View) ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView)

Example 27 with ObservableListView

use of com.github.ksoichiro.android.observablescrollview.ObservableListView in project UltimateAndroid by cymcsg.

the class ViewPagerTabListViewActivity method onUpOrCancelMotionEvent.

@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    mBaseTranslationY = 0;
    Fragment fragment = getCurrentFragment();
    if (fragment == null) {
        return;
    }
    View view = fragment.getView();
    if (view == null) {
        return;
    }
    int toolbarHeight = mToolbarView.getHeight();
    final ObservableListView listView = (ObservableListView) view.findViewById(R.id.list);
    if (scrollState == ScrollState.UP) {
        if (toolbarHeight < listView.getCurrentScrollY()) {
            hideToolbar();
        } else if (listView.getCurrentScrollY() < toolbarHeight) {
            showToolbar();
        }
    } else if (scrollState == ScrollState.DOWN) {
        if (toolbarHeight < listView.getCurrentScrollY()) {
            showToolbar();
        }
    }
}
Also used : ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView) Fragment(android.support.v4.app.Fragment) View(android.view.View) ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView)

Example 28 with ObservableListView

use of com.github.ksoichiro.android.observablescrollview.ObservableListView in project UltimateAndroid by cymcsg.

the class ViewPagerTabListViewActivity method propagateToolbarState.

private void propagateToolbarState(boolean isShown) {
    int toolbarHeight = mToolbarView.getHeight();
    // Set scrollY for the fragments that are not created yet
    mPagerAdapter.setScrollY(isShown ? 0 : toolbarHeight);
    // Set scrollY for the active fragments
    for (int i = 0; i < mPagerAdapter.getCount(); i++) {
        // Skip current item
        if (i == mPager.getCurrentItem()) {
            continue;
        }
        // Skip destroyed or not created item
        Fragment f = mPagerAdapter.getItemAt(i);
        if (f == null) {
            continue;
        }
        ObservableListView listView = (ObservableListView) f.getView().findViewById(R.id.list);
        if (isShown) {
            // Scroll up
            if (0 < listView.getCurrentScrollY()) {
                listView.setSelection(0);
            }
        } else {
            // Scroll down (to hide padding)
            if (listView.getCurrentScrollY() < toolbarHeight) {
                listView.setSelection(1);
            }
        }
    }
}
Also used : ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView) Fragment(android.support.v4.app.Fragment)

Example 29 with ObservableListView

use of com.github.ksoichiro.android.observablescrollview.ObservableListView in project Osmand by osmandapp.

the class MapMultiSelectionMenuFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    menu = ((MapActivity) getActivity()).getContextMenu().getMultiSelectionMenu();
    view = inflater.inflate(R.layout.menu_obj_selection_fragment, container, false);
    if (menu.isLandscapeLayout()) {
        AndroidUtils.setBackground(view.getContext(), view, !menu.isLight(), R.drawable.multi_selection_menu_bg_light_land, R.drawable.multi_selection_menu_bg_dark_land);
    } else {
        AndroidUtils.setBackground(view.getContext(), view.findViewById(R.id.cancel_row), !menu.isLight(), R.color.ctx_menu_bg_light, R.color.ctx_menu_bg_dark);
    }
    final ListView listView = (ListView) view.findViewById(R.id.list);
    if (menu.isLandscapeLayout() && Build.VERSION.SDK_INT >= 21) {
        AndroidUtils.addStatusBarPadding21v(getActivity(), listView);
    }
    listAdapter = createAdapter();
    listAdapter.setListener(this);
    if (!menu.isLandscapeLayout()) {
        final Context context = getContext();
        FrameLayout paddingView = new FrameLayout(context);
        paddingView.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, getPaddingViewHeight()));
        paddingView.setClickable(true);
        paddingView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                dismissMenu();
            }
        });
        FrameLayout shadowContainer = new FrameLayout(context);
        shadowContainer.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT, Gravity.BOTTOM));
        ImageView shadow = new ImageView(context);
        shadow.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.bg_shadow_onmap));
        shadow.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM));
        shadow.setScaleType(ImageView.ScaleType.FIT_XY);
        shadowContainer.addView(shadow);
        paddingView.addView(shadowContainer);
        listView.addHeaderView(paddingView);
        view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {
                float titleHeight = getResources().getDimension(R.dimen.multi_selection_header_height);
                int maxHeight = (int) (titleHeight);
                for (int i = 0; i < 3 && i < listAdapter.getCount(); i++) {
                    View childView = listAdapter.getView(0, null, (ListView) view.findViewById(R.id.list));
                    childView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
                    maxHeight += childView.getMeasuredHeight();
                }
                listView.setSelectionFromTop(0, -maxHeight);
                ViewTreeObserver obs = view.getViewTreeObserver();
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    obs.removeOnGlobalLayoutListener(this);
                } else {
                    obs.removeGlobalOnLayoutListener(this);
                }
            }
        });
        ((ObservableListView) listView).setScrollViewCallbacks(new ObservableScrollViewCallbacks() {

            boolean initialScroll = true;

            int minHeight = getResources().getDimensionPixelSize(R.dimen.multi_selection_header_height) + getResources().getDimensionPixelSize(R.dimen.list_item_height);

            @Override
            public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
                if (scrollY <= minHeight && !initialScroll) {
                    dismissMenu();
                }
            }

            @Override
            public void onDownMotionEvent() {
                initialScroll = false;
            }

            @Override
            public void onUpOrCancelMotionEvent(ScrollState scrollState) {
            }
        });
    }
    listView.setAdapter(listAdapter);
    View headerView = inflater.inflate(R.layout.menu_obj_selection_header, listView, false);
    if (!menu.isLandscapeLayout()) {
        AndroidUtils.setBackground(getContext(), headerView, !menu.isLight(), R.color.ctx_menu_bg_light, R.color.ctx_menu_bg_dark);
    }
    headerView.setOnClickListener(null);
    listView.addHeaderView(headerView);
    view.findViewById(R.id.divider).setBackgroundColor(ContextCompat.getColor(getContext(), menu.isLight() ? R.color.multi_selection_menu_divider_light : R.color.multi_selection_menu_divider_dark));
    ((TextView) view.findViewById(R.id.cancel_row_text)).setTextColor(ContextCompat.getColor(getContext(), menu.isLight() ? R.color.multi_selection_menu_close_btn_light : R.color.multi_selection_menu_close_btn_dark));
    view.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            dismissMenu();
        }
    });
    return view;
}
Also used : Context(android.content.Context) AbsListView(android.widget.AbsListView) ObservableScrollViewCallbacks(com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks) ImageView(android.widget.ImageView) View(android.view.View) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) ListView(android.widget.ListView) ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView) ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView) AbsListView(android.widget.AbsListView) ListView(android.widget.ListView) ObservableListView(com.github.ksoichiro.android.observablescrollview.ObservableListView) FrameLayout(android.widget.FrameLayout) ScrollState(com.github.ksoichiro.android.observablescrollview.ScrollState) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ViewTreeObserver(android.view.ViewTreeObserver) MapActivity(net.osmand.plus.activities.MapActivity) Nullable(android.support.annotation.Nullable)

Aggregations

ObservableListView (com.github.ksoichiro.android.observablescrollview.ObservableListView)29 View (android.view.View)18 AbsListView (android.widget.AbsListView)11 ObservableScrollViewCallbacks (com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks)7 Activity (android.app.Activity)5 Fragment (android.support.v4.app.Fragment)5 Bundle (android.os.Bundle)4 SuppressLint (android.annotation.SuppressLint)3 TextView (android.widget.TextView)3 ArrayList (java.util.ArrayList)3 ViewTreeObserver (android.view.ViewTreeObserver)2 Context (android.content.Context)1 Nullable (android.support.annotation.Nullable)1 ViewGroup (android.view.ViewGroup)1 AdapterView (android.widget.AdapterView)1 FrameLayout (android.widget.FrameLayout)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 ScrollState (com.github.ksoichiro.android.observablescrollview.ScrollState)1 MapActivity (net.osmand.plus.activities.MapActivity)1