예제 #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.MainLayout);

            // inject views
            Geneticist.Splice(this);

            // set up chrome
            drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, Resource.String.drawer_open, Resource.String.drawer_close);
            drawerLayout.SetDrawerListener(drawerToggle);
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SupportActionBar.SetHomeButtonEnabled(true);

            //var styledAttributes = Theme.ObtainStyledAttributes(new[] { Android.Resource.Attribute.ActionBarSize });
            //var actionBarSize = (int)styledAttributes.GetDimension(0, 0);
            //styledAttributes.Recycle();

            // set up list view
            stickyList.EmptyView = FindViewById(Resource.Id.empty);
            stickyList.DrawingListUnderStickyHeader = true;
            stickyList.AreHeadersSticky             = true;
            stickyList.StickyHeaderTopOffset        = 0;// -20;
            stickyList.AddHeaderView(LayoutInflater.Inflate(Resource.Layout.ListHeader, null));
            stickyList.AddFooterView(LayoutInflater.Inflate(Resource.Layout.ListFooter, null));
            stickyList.ItemClick += (sender, e) =>
                                    Toast.MakeText(this, "Item " + e.Position + " clicked!", ToastLength.Short).Show();
            stickyList.HeaderClick += (sender, e) =>
                                      Toast.MakeText(this, "Header " + e.HeaderId + " currentlySticky ? " + e.CurrentlySticky, ToastLength.Short).Show();
            stickyList.StickyHeaderChanged       += (sender, e) => ViewHelper.SetAlpha(e.Header, 1);
            stickyList.StickyHeaderOffsetChanged += (sender, e) =>
            {
                if (fadeHeader)
                {
                    ViewHelper.SetAlpha(e.Header, 1 - (e.Offset / (float)e.Header.MeasuredHeight));
                }
            };

            // set up data
            adapter            = new StickyAdapter(this);
            stickyList.Adapter = adapter;

            // actions
            openExpandableListButton.Click += (sender, e) => StartActivity(new Intent(this, typeof(ExpandableListActivity)));
            restoreButton.Click            += (sender, e) => adapter.Restore();
            updateButton.Click             += (sender, e) => adapter.NotifyDataSetChanged();
            clearButton.Click                += (sender, e) => adapter.Clear();
            stickyCheckBox.CheckedChange     += (sender, e) => stickyList.AreHeadersSticky = e.IsChecked;
            fadeCheckBox.CheckedChange       += (sender, e) => fadeHeader = e.IsChecked;
            drawBehindCheckBox.CheckedChange += (sender, e) => stickyList.DrawingListUnderStickyHeader = e.IsChecked;
            fastScrollCheckBox.CheckedChange += (sender, e) =>
            {
                stickyList.SetFastScrollEnabled(e.IsChecked);
                stickyList.FastScrollAlwaysVisible = e.IsChecked;
            };
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.ExpandableLayout);

            // inject views
            Geneticist.Splice(this);

            // handle header clicks
            listView.HeaderClick += (sender, e) =>
            {
                if (listView.IsHeaderCollapsed(e.HeaderId))
                {
                    listView.Expand(e.HeaderId);
                }
                else
                {
                    listView.Collapse(e.HeaderId);
                }
            };

            //custom expand/collapse animation
            listView.SetAnimExecutor((target, animType) =>
            {
                if (ExpandableStickyListHeadersListView.AnimationExpand == animType &&
                    target.Visibility == ViewStates.Visible)
                {
                    return;
                }
                if (ExpandableStickyListHeadersListView.AnimationCollapse == animType &&
                    target.Visibility != ViewStates.Visible)
                {
                    return;
                }
                if (!originalHeightPool.ContainsKey(target.Handle))
                {
                    originalHeightPool.Add(target.Handle, target.Height);
                }

                var viewHeight    = originalHeightPool[target.Handle];
                var animStartY    = animType == ExpandableStickyListHeadersListView.AnimationExpand ? 0f : viewHeight;
                var animEndY      = animType == ExpandableStickyListHeadersListView.AnimationExpand ? viewHeight : 0f;
                target.Visibility = ViewStates.Visible;
                var lp            = target.LayoutParameters;
                var animator      = ValueAnimator.OfFloat(animStartY, animEndY);
                animator.SetDuration(200);
                animator.AnimationEnd += delegate
                {
                    if (animType == ExpandableStickyListHeadersListView.AnimationExpand)
                    {
                        target.Visibility = ViewStates.Visible;
                    }
                    else
                    {
                        target.Visibility = ViewStates.Gone;
                    }
                    target.LayoutParameters.Height = viewHeight;
                };
                animator.Update += delegate
                {
                    lp.Height = (int)animator.AnimatedValue;
                    target.LayoutParameters = lp;
                    target.RequestLayout();
                };
                animator.Start();
            });

            // set up data
            adapter          = new StickyAdapter(this);
            listView.Adapter = adapter;
        }