/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Collections; using System.Collections.Generic; using System.Text; namespace ElmSharp.Wearable { class MoreOptionList : IList { MoreOption Owner { get; set; } List Items { get; set; } /// /// Sets or gets the count of items. /// public int Count => Items.Count; /// /// Sets or gets whether it is read-only. /// public bool IsReadOnly => false; /// /// Sets or gets the item with the index. /// /// The position of item in items. /// MoreOptionItem object on the index. public MoreOptionItem this[int index] { get { return Items[index]; } set { Items[index] = value; } } /// /// Creates and initializes a new instance of the MoreOptionList class. /// /// The object of more option. public MoreOptionList(MoreOption owner) { Owner = owner; Items = new List(); } /// /// Appends a new item to the more option. /// /// The more option item. public void Add(MoreOptionItem item) { item.Handle = Interop.Eext.eext_more_option_item_append(Owner); Items.Add(item); } /// /// Adds a new item to the more option at the first. /// /// The more option item. public void AddFirst(MoreOptionItem item) { item.Handle = Interop.Eext.eext_more_option_item_prepend(Owner); Items.Insert(0, item); } /// /// Adds a new item to the more option at the last. /// /// The more option item. public void AddLast(MoreOptionItem item) { Add(item); } /// /// Get the index of an item. /// /// The more option item. /// The index of an item. public int IndexOf(MoreOptionItem item) { return Items.IndexOf(item); } /// /// Inserts a new item into the more option, after the more option item with the index. /// /// The index of an item, which is inserted after. /// The more option item. public void Insert(int index, MoreOptionItem item) { if (Items.Count < index + 1 || index < 0) throw new ArgumentOutOfRangeException("index is not valid in the MoreOption"); MoreOptionItem target = Items[index]; item.Handle = Interop.Eext.eext_more_option_item_insert_after(Owner, target.Handle); Items.Insert(index, item); } /// /// Deletes an item, which is the given item index. /// /// the item index which will be deleted public void RemoveAt(int index) { if (Items.Count < index + 1 || index < 0) throw new ArgumentOutOfRangeException("index is not valid in the MoreOptionList"); MoreOptionItem item = Items[index]; Interop.Eext.eext_more_option_item_del(item.Handle); item.Handle = IntPtr.Zero; Items.RemoveAt(index); } /// /// Removes all the items from a given more option list object. /// public void Clear() { Interop.Eext.eext_more_option_items_clear(Owner); foreach (MoreOptionItem item in Items) { item.Handle = IntPtr.Zero; } Items.Clear(); } /// /// Checks the item whether it is contained. /// /// The more option item. /// If contained return true, otherwise false. public bool Contains(MoreOptionItem item) { return Items.Contains(item); } /// /// Copies the items. /// /// The target array. /// The index to which the item will be copied. public void CopyTo(MoreOptionItem[] array, int arrayIndex) { Items.CopyTo(array, arrayIndex); } /// /// Removes the item. /// /// The item will be removed. /// If removed is successful return true, otherwise false. public bool Remove(MoreOptionItem item) { if (Items.Contains(item)) { Interop.Eext.eext_more_option_item_del(item.Handle); Items.Remove(item); return true; } return false; } /// /// Returns an enumerator that iterates through IEnumerator. /// /// public IEnumerator GetEnumerator() { return Items.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return Items.GetEnumerator(); } } }