Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- [Activity(Label = "@string/AppTitle", ConfigurationChanges = ConfigChanges.Orientation)]
- public class RemainsActivity : BaseTabActivity
- {
- internal class Parameters
- {
- // Входные параметры
- internal static Guid VisitID;
- internal static Guid ShopID;
- internal static Guid savedInvoiceID = TypeExtra.GuidNull;
- internal static Guid ProductTreeID;
- internal static TreeType TreeType;
- internal static List<Guid> TempInvoices = new List<Guid>();
- internal static bool UpdateCategoryProducts;
- internal static bool UpdateInvoiceProducts;
- private static List<Product> categoryProducts = new List<Product>();
- internal static List<Product> CategoryProducts
- {
- get { return categoryProducts; }
- set { categoryProducts = (value ?? new List<Product>()); } //
- }
- private static List<Product> invoiceProducts = new List<Product>();
- internal static List<Product> InvoiceProducts
- {
- get { return invoiceProducts; }
- set { invoiceProducts = (value ?? new List<Product>()); } //
- }
- private static List<InvoiceProduct> lastPrices = new List<InvoiceProduct>();
- internal static List<InvoiceProduct> LastPrices
- {
- get { return lastPrices; }
- set { lastPrices = (value ?? new List<InvoiceProduct>()); } //
- }
- internal static TabHost TabHost;
- internal static void Set(Guid visitID, Guid shopID)
- {
- Reset();
- VisitID = visitID;
- ShopID = shopID;
- Settings.User.CurrentInvoiceType = InvoiceType.Enum.MerchCurrentRemainsAndPrices;
- }
- internal static void Reset()
- {
- TempInvoices.Clear();
- CategoryProducts.Clear();
- InvoiceProducts.Clear();
- ProductTreeID = TypeExtra.GuidNull;
- UpdateCategoryProducts = false;
- UpdateInvoiceProducts = false;
- }
- }
- private const int TabWidgetHeightDP = 35;
- private const string categoryTabID = "Category";
- private const string invoiceTabID = "Invoice";
- private TabHost.TabSpec categoryWidget = null;
- private TabHost.TabSpec invoiceWidget = null;
- protected override void OnCreate(Bundle bundle)
- {
- base.OnCreate(bundle);
- RemainsActivity.Parameters.savedInvoiceID = TypeExtra.GuidNull;
- if (bundle != null)
- if (RemainsActivity.Parameters.VisitID == null)
- {
- if (bundle.ContainsKey("Parameters.savedInvoiceID"))
- RemainsActivity.Parameters.savedInvoiceID = new Guid(bundle.GetString("Parameters.savedInvoiceID"));
- string ID;
- ID = bundle.GetString("Parameters.ProductTreeID");
- if (!string.IsNullOrEmpty(ID))
- {
- bundle.Remove("Parameters.ProductTreeID");
- RemainsActivity.Parameters.ProductTreeID = new Guid(ID);
- }
- ID = bundle.GetString("Parameters.VisitID");
- if (!string.IsNullOrEmpty(ID))
- {
- string ShopID = bundle.GetString("Parameters.ShopID");
- RemainsActivity.Parameters.Set(new Guid(ID), new Guid(ShopID));
- bundle.Remove("Parameters.VisitID");
- bundle.Remove("Parameters.ShopID");
- }
- ID = bundle.GetString("Parameters.ProductTreeID");
- if (!string.IsNullOrEmpty(ID))
- {
- bundle.Remove("Parameters.ProductTreeID");
- RemainsActivity.Parameters.ProductTreeID = new Guid(ID);
- }
- }
- SetContentView(Resource.Layout.RemainsActivity);
- // Select
- var intent = new Intent(this, typeof(RemainsActivity_CategoryTab));
- intent.AddFlags(ActivityFlags.NewTask);
- categoryWidget = TabHost.NewTabSpec(categoryTabID);
- categoryWidget.SetIndicator(GetString(Resource.String.TabTitle_Select));
- categoryWidget.SetContent(intent);
- TabHost.AddTab(categoryWidget);
- // Invoice
- intent = new Intent(this, typeof(RemainsActivity_InvoiceTab));
- intent.AddFlags(ActivityFlags.NewTask);
- invoiceWidget = TabHost.NewTabSpec(invoiceTabID);
- invoiceWidget.SetIndicator(GetString(Resource.String.TabTitle_Remains));
- invoiceWidget.SetContent(intent);
- TabHost.AddTab(invoiceWidget);
- for (int i = 0; i < TabHost.TabWidget.ChildCount; i++)
- {
- //var image = ((RelativeLayout)TabHost.TabWidget.GetChildAt(i)).GetChildAt(0);
- //var tv = ((RelativeLayout)TabHost.TabWidget.GetChildAt(i)).GetChildAt(1);
- //((RelativeLayout)TabHost.TabWidget.GetChildAt(i)).RemoveViewAt(0);
- var rl = TabHost.TabWidget.GetChildAt(i);
- rl.LayoutParameters.Height = (int)(TabWidgetHeightDP * Resources.DisplayMetrics.Density + 0.5f);
- }
- TabHost.CurrentTab = 0;
- TabHost.TabChanged += new EventHandler<Android.Widget.TabHost.TabChangeEventArgs>(TabHost_TabChanged);
- Parameters.TabHost = TabHost;
- }
- protected override void OnRestart()
- {
- if (Parameters.TabHost != null)
- Parameters.TabHost.Dispose();
- base.OnRestart();
- }
- protected override void OnSaveInstanceState(Bundle outState)
- {
- Log.Debug("OnSaveInstanceState Remains Category Tab Activity");
- if (RemainsActivity.Parameters.VisitID != null)
- outState.PutString("Parameters.VisitID", RemainsActivity.Parameters.VisitID.ToString());
- if (RemainsActivity.Parameters.ShopID != null)
- outState.PutString("Parameters.ShopID", RemainsActivity.Parameters.ShopID.ToString());
- if (RemainsActivity.Parameters.ProductTreeID != null)
- outState.PutString("Parameters.ProductTreeID", RemainsActivity.Parameters.ProductTreeID.ToString());
- if (Parameters.savedInvoiceID != null)
- outState.PutString("Parameters.savedInvoiceID", RemainsActivity.Parameters.savedInvoiceID.ToString());
- base.OnSaveInstanceState(outState);
- }
- <mobileagent.customcontrols.ProductTreeView
- android:id="@+id/RemainsActivity_CategoryTab_ProductTreeView"
- android:layout_height="wrap_content"
- android:layout_width="match_parent" />
- `<?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android=""
- xmlns:app=""
- android:tag="RemainsActivity_CategoryTab"
- android:id="@+id/RemainsActivity_CategoryTab_RootLayout"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <LinearLayout
- android:id="@+id/RemainsActivity_CategoryTab_MainLayout"
- android:layout_height="match_parent"
- android:layout_width="match_parent"
- android:orientation="vertical"
- android:layout_weight="1">
- <app1.customcontrols.DrawnDataGrid
- android:id="@+id/RemainsActivity_CategoryTab_DataGrid"
- android:layout_height="match_parent"
- android:layout_width="wrap_content"
- android:layout_weight="1"
- android:tag="RemainsActivity_CategoryTab_DataGrid">
- <!-- DataGrid Header-->
- <app1.customcontrols.DrawnDataGridHeader
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- <app1.customcontrols.DataGridColumn
- app:mapping="ProductName"
- android:text="@string/ProductName"
- android:layout_width="200dp"
- android:layout_height="25dp"
- style="@style/DataGridHeader.First" />
- <app1.customcontrols.DataGridColumn
- app:mapping="TotalProductQuantity"
- app:format="{FractionInUnitsFormat}"
- android:text="@string/Quantity"
- android:layout_width="50dp"
- android:layout_height="25dp"
- app:cellgravity="right"
- style="@style/DataGridHeader.Next" />
- <app1.customcontrols.DataGridColumn
- app:mapping="CustomPrice"
- app:format="{0:0.00}"
- android:text="@string/Price"
- android:layout_width="50dp"
- android:layout_height="25dp"
- app:cellgravity="right"
- style="@style/DataGridHeader.Next" />
- </app1.customcontrols.DrawnDataGridHeader>
- </app1.customcontrols.DrawnDataGrid>
- <!-- Product Info -->
- <TextView
- android:id="@+id/RemainsActivity_CategoryTab_ProductInfoTextView"
- android:hint="@string/Hint_ProductInfo"
- android:layout_height="wrap_content"
- android:layout_width="match_parent" />
- <!-- Edit Text Controls -->
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <ImageButton
- android:src="@drawable/tb_product_tree"
- android:scaleType="centerInside"
- android:id="@+id/RemainsActivity_CategoryTab_ProductTreeButton"
- android:layout_height="@dimen/productTreeButtonSize"
- android:layout_width="@dimen/productTreeButtonSize"
- android:layout_gravity="center_vertical" />
- <EditText
- android:text=""
- android:hint="@string/Blocks"
- android:id="@+id/RemainsActivity_CategoryTab_BlocksEditText"
- android:singleLine="true"
- android:layout_weight="0.3"
- android:numeric="decimal"
- android:selectAllOnFocus="true"
- android:imeOptions="flagNoExtractUi"
- android:layout_height="wrap_content"
- android:layout_width="wrap_content" />
- <EditText
- android:text=""
- android:hint="@string/Units"
- android:id="@+id/RemainsActivity_CategoryTab_UnitsEditText"
- android:singleLine="true"
- android:layout_weight="0.3"
- android:numeric="decimal"
- android:inputType="numberDecimal"
- android:digits="0123456789.,"
- android:selectAllOnFocus="true"
- android:imeOptions="flagNoExtractUi"
- android:layout_height="wrap_content"
- android:layout_width="wrap_content" />
- <EditText
- android:text=""
- android:hint="@string/Price"
- android:id="@+id/RemainsActivity_CategoryTab_PriceEditText"
- android:singleLine="true"
- android:layout_weight="0.3"
- android:numeric="decimal"
- android:inputType="numberDecimal"
- android:digits="0123456789.,"
- android:selectAllOnFocus="true"
- android:imeOptions="flagNoExtractUi"
- android:layout_height="wrap_content"
- android:layout_width="wrap_content" />
- </LinearLayout>
- <!-- NumPad -->
- <app1.customcontrols.NumPad
- android:id="@+id/NumPad"
- android:layout_height="wrap_content"
- android:layout_width="match_parent" />
- </LinearLayout>
- <app1.customcontrols.ProductTreeView
- android:id="@+id/RemainsActivity_CategoryTab_ProductTreeView"
- android:layout_height="wrap_content"
- android:layout_width="match_parent" />
- <app1.CustomControls.MenuButtonPanel
- android:id="@+id/RemainsActivity_CategoryTab_MenuButtonPanel"
- android:layout_height="wrap_content"
- android:layout_width="match_parent" />
- </LinearLayout>`
- private bool selected = false;
- private Product Selected = null;
- private Product InvoiceProduct = null;
- //{
- // get
- // {
- // if (productsDataGrid.SelectedIndex == -1)
- // return null;
- // else
- // return categoryProducts[productsDataGrid.SelectedIndex];
- // }
- //}
- private DrawnDataGrid dataGrid;
- private TextView productInfoTextView;
- private ImageButton productTreeButton;
- private EditText blocksEditText;
- private EditText unitsEditText;
- private EditText priceEditText;
- private LinearLayout mainLayout;
- private ProductTreeView productTreeView;
- protected override void OnCreate(Bundle bundle)
- {
- try
- {
- base.OnCreate(bundle);
- if (CheckWasInBackground()) return;
- SetContentView(Resource.Layout.RemainsActivity_CategoryTab);
- BindMenuButtonClicked(Resource.Id.RemainsActivity_CategoryTab_MenuButtonPanel);
- dataGrid = FindViewById<DrawnDataGrid>(Resource.Id.RemainsActivity_CategoryTab_DataGrid);
- dataGrid.SelectedChanged += new EventHandler(dataGrid_SelectedChanged);
- productInfoTextView = FindViewById<TextView>(Resource.Id.RemainsActivity_CategoryTab_ProductInfoTextView);
- productTreeButton = FindViewById<ImageButton>(Resource.Id.RemainsActivity_CategoryTab_ProductTreeButton);
- productTreeButton.Click += new EventHandler(OnProductTreeButtonClick);
- blocksEditText = FindViewById<EditText>(Resource.Id.RemainsActivity_CategoryTab_BlocksEditText);
- blocksEditText.TextChanged += new EventHandler<Android.Text.TextChangedEventArgs>(OnQuantityChanged);
- unitsEditText = FindViewById<EditText>(Resource.Id.RemainsActivity_CategoryTab_UnitsEditText);
- unitsEditText.TextChanged += new EventHandler<Android.Text.TextChangedEventArgs>(OnQuantityChanged);
- priceEditText = FindViewById<EditText>(Resource.Id.RemainsActivity_CategoryTab_PriceEditText);
- priceEditText.TextChanged += OnPriceChanged;
- mainLayout = FindViewById<LinearLayout>(Resource.Id.RemainsActivity_CategoryTab_MainLayout);
- productTreeView = FindViewById<ProductTreeView>(Resource.Id.RemainsActivity_CategoryTab_ProductTreeView);
- productTreeView.TreeItemSelected += new EventHandler(OnTreeItemSelected);
- productTreeView.Hide();
- Init();
- OnCreateFinished();
- }
- catch (Exception ex)
- {
- Log.Exception(ex);
- throw;
- }
- }
- private TreeView mTreeView;
- private bool mAlternative = false;
- private bool loaded = false;
- internal event EventHandler TreeItemSelected;
- internal Guid SelectedProductTreeID
- {
- get { return mTreeView.SelectedID != null ? (Guid)mTreeView.SelectedID : TypeExtra.GuidNull; }
- }
- internal TreeType SelectedTreeType
- {
- get { return mTreeView.SelectedTreeType; }
- }
- internal string SelectedText
- {
- get { return SelectedProductTreeID != TypeExtra.GuidNull ? mTreeView.SelectedText : Context.GetString(Resource.String.AllProductTrees); }
- }
- public ProductTreeView(Context context, IAttributeSet attrs) :
- base(context, attrs)
- {
- Init(context, attrs);
- }
- public ProductTreeView(Context context, bool isAlternative, IAttributeSet attrs) :
- base(context, attrs)
- {
- mAlternative = isAlternative;
- Init(context, attrs);
- }
- private void Init(Context context, IAttributeSet attrs)
- {
- mHorizontalScrollView = new HorizontalScrollView(context, attrs);
- AddView(mHorizontalScrollView, new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent));
- mTreeView = new TreeView(context, attrs);
- mHorizontalScrollView.AddView(mTreeView, new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent));
- mTreeView.SelectedChanged += new EventHandler(treeView_SelectedChanged);
- mTreeView.ParentSelectedChanged += new EventHandler(treeView_ParentSelectedChanged);
- }
- Сlass TreeView:
- public class TreeView : LinearLayout
- {
- private List<List<ITreeItem>> trees = new List<List<ITreeItem>>();
- private Hashtable itemsByID = new Hashtable();
- private Hashtable treeIndexesByID = new Hashtable();
- private Hashtable treeTypesByTreeIndex = new Hashtable();
- private TreeViewItem SelectedItem;
- internal object SelectedID
- {
- get
- {
- if (SelectedItem == null)
- {
- return null;
- }
- else
- {
- return SelectedItem.ID;
- }
- }
- }
- internal string SelectedText
- {
- get
- {
- if (SelectedItem == null)
- {
- return null;
- }
- else
- {
- return SelectedItem.Text;
- }
- }
- }
- internal TreeType SelectedTreeType
- {
- get
- {
- if (SelectedItem == null)
- {
- return TreeType.None;
- }
- else
- {
- var idx = treeIndexesByID[SelectedItem.ID];
- return (TreeType)treeTypesByTreeIndex[idx];
- }
- }
- }
- internal event EventHandler SelectedChanged;
- internal event EventHandler ParentSelectedChanged;
- #region Colors
- protected Color backgroundColorNotSelected = Color.AliceBlue;
- protected Color BackgroundColorNotSelected
- {
- get
- {
- if (backgroundColorNotSelected == Color.AliceBlue)
- {
- TypedValue tv = new TypedValue();
- Context.Theme.ResolveAttribute(Android.Resource.Attribute.ColorBackground, tv, true);
- backgroundColorNotSelected = Resources.GetColor(tv.ResourceId);
- }
- return backgroundColorNotSelected;
- }
- }
- protected Color backgroundColorSelected = Color.AliceBlue;
- protected Color BackgroundColorSelected
- {
- get
- {
- if (backgroundColorSelected == Color.AliceBlue)
- {
- TypedValue tv = new TypedValue();
- Context.Theme.ResolveAttribute(Android.Resource.Attribute.TextColorSecondaryInverse, tv, true);
- backgroundColorSelected = Resources.GetColor(tv.ResourceId);
- }
- return backgroundColorSelected;
- }
- }
- #endregion
- public TreeView(Context context, IAttributeSet attrs) :
- base(context, attrs)
- {
- Orientation = Orientation.Vertical;
- }
Add Comment
Please, Sign In to add comment