Click here to Skip to main content
15,884,986 members
Articles / Mobile Apps

Windows Mobile Password Safe

Rate me:
Please Sign up or sign in to vote.
4.87/5 (58 votes)
12 Jan 2009CPOL16 min read 159.4K   3.1K   139  
A password safe with a touch screen UI introducing Fluid Controls.
using System;

using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using Fluid.Classes;

namespace Fluid.Controls
{
    public partial class FluidListBox
    {
        private bool animateInsertDelete = false;

        /// <summary>
        /// Gets or sets whether an animation is performed if an item is inserted or removed from the datasource if it is a IBindingList.
        /// </summary>
        public bool EnableInsertDeleteAnimation { get { return animateInsertDelete; } set { animateInsertDelete = value; } }

        private void ConnectBindingList(IBindingList list)
        {
            if (list != null)
            {
                list.ListChanged += new ListChangedEventHandler(BindingListChanged);
            }
        }

        void BindingListChanged(object sender, ListChangedEventArgs e)
        {
            switch (e.ListChangedType)
            {
                case ListChangedType.ItemAdded:
                    ShowHeader = GetItem(0) is IGroupHeader;
                    AddBindingItem(this.items[e.NewIndex], e.NewIndex);
                    break;

                case ListChangedType.ItemDeleted:
                    //                    ResetBindingList();
                    ShowHeader = GetItem(0) is IGroupHeader;
                    RemoveBindingItem(e.NewIndex);
                    break;

                case ListChangedType.ItemMoved:
                case ListChangedType.Reset:
                    ResetBindingList();
                    break;
            }
        }

        private void ResetBindingList()
        {
            StopAnimations();
            StopAutoScroll();

            ShowHeader = GetItem(0) is IGroupHeader;
            RecalulateItemOffsets();
            TopOffset = 0;
            SelectFirstDataItem();
            Invalidate();
        }

        /// <summary>
        /// Selects the first item that is no IGroupHeader.
        /// </summary>
        public void SelectFirstDataItem()
        {
            if (items == null) return;

            for (int i = 0; i < items.Count; i++)
            {
                object o = items[i];
                if (!(o is IGroupHeader))
                {
                    SelectedItemIndex = i;
                    return;
                }
            }
            SelectedItemIndex = 0;
        }

        private List<Animation> bindingAnimations = new List<Animation>();

        private void AddBindingItem(object item, int index)
        {
            int offset = itemOffsets[index];
            itemOffsets.Insert(index + 1, offset);
            int h = GetItemHeight(item);
            if (EnableInsertDeleteAnimation)
            {
                //ModifyAnimations(index + 1, 1);
                animIndex=index+1;
                Animation.LogAnimation(0, h, Animation.DefaultDuration, BindingScene);
            }
            else
            {
                OffseItemTops(index + 1, h);
            }
        }

        /// <summary>
        /// Performs an animation when an item was removed from the datasource as IBIndingList.
        /// </summary>
        /// <param name="index"></param>
        private void RemoveBindingItem(int index)
        {
            if (index < items.Count)
            {

                if (true || EnableInsertDeleteAnimation)
                {
                   // ModifyAnimations(index, -1);
                    int h0 = GetItemHeight(index);
                    itemOffsets.RemoveAt(index);
                    int h1 = index > 0 ? GetItemHeight(index - 1) : h0;
                    int h2 = h1 - h0;
                    animIndex = index;
                    Animation.LogAnimation(h1, h2, 150, BindingScene);
                }
                else
                {
                    int h = GetItemHeight(index);
                    itemOffsets.RemoveAt(index);
                    OffseItemTops(index, -h);
                    Invalidate();
                }
            }
            else
            {
                itemOffsets.RemoveAt(index + 1);
                Invalidate();
            }
        }

        private int animIndex;

        private bool IsItemAnimating(int index)
        {
            foreach (Animation a in bindingAnimations)
            {
                int idx = (int)a.Data;
                if (idx == index) return true;
            }
            return false;
        }

        private void ModifyAnimations(int index, int offset)
        {
            Animation[] array = bindingAnimations.ToArray();
            foreach (Animation a in array)
            {
                int idx = (int)a.Data;

                if (idx > index) a.Data = idx + offset;
                else if (idx == index)
                {
                    if (offset < 0) a.Stop(); else a.Data = idx + offset;
                }
            }
        }

        private void OffseItemTops(int index, int delta)
        {
            if (delta == 0) return;
            for (int i = index; i < itemOffsets.Count; i++)
            {
                itemOffsets[i] += delta;
            }
        }

        private void OffseDeltaItemTops(int index, int h)
        {
            int h0 = index > 0 ? GetItemHeight(index - 1) : itemOffsets[0];
            int delta = h - h0;
            OffseItemTops(index, delta);
        }


        void BindingScene(object sender, AnimationEventArgs e)
        {
            Animation a = (Animation)sender;
            int index = animIndex;
            OffseDeltaItemTops(index, e.Value);

            Invalidate();
            Update();
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Germany Germany
MCPD
Enterprise Application Developer 3.5
Windows Developer 3.5
.ASP.NET Developer 3.5
.NET 2.0 Windows Developer
.NET 2.0 Web Developer
.NET 2.0 Enterprise Application Developer


MCTS
.NET 3.5 Windows Forms Applications
.NET 3.5 ASP.NET Applications
.NET 3.5, ADO.NET Application Development
.NET 3.5 WCF
.NET 3.5 WPF
.NET 3.5 WF
Microsoft SQL Server 2008, Database Development
.NET 2.0 Windows Applications
.NET 2.0 Web Applications
.NET 2.0 Distributed Applications
SQL Server 2005
Sharepoint Services 3.0 Application Development
Windows Vista Client Configuration

Comments and Discussions