示例#1
0
        private Tab CreateTab(string name, string tag, string gaugeType, string size, Tab tab = null)
        {
            ActionBar.Tab aTab = ActionBar.NewTab();
            aTab.SetText(name);

            if (tab == null)
            {
                tab = new Tab(
                    name,
                    aTab,
                    name == "Total" ? new Trip(true) : trip);

                tabs.Add(tab);
            }
            else
            {
                tab.ActionBarTab = aTab;
            }
            tab.include = parser.GetValues(tag);
            if (name == "Eff")
            {
                tab.include =
                    tab.include.OrderBy(x => x.unit.Trim()).ToList();
            }
            tab.size  = int.Parse(size);
            tab.style = int.Parse(gaugeType);
            if (name == "BMS")
            {
                tab.style = 3;
            }

            aTab.TabSelected += (sender, args) => {
                currentTab = tab;
                if (bluetoothHandler.active)
                {
                    bluetoothHandler.ChangeFilter(currentTab.include);
                }
                ladapter.items = currentTab.GetItems(parser);
                ladapter.items.Any(x => x.selected = false);
                gridView1.NumColumns = currentTab.style == 0 ? 1 : currentTab.size;
                gridView1.Invalidate();
                ladapter.NotifyChange();
                if (!starting)
                {
                    editor = prefs.Edit();
                    editor.PutString("currentTab", currentTab.name);
                    editor.Commit();
                }
            };
            ActionBar.AddTab(aTab);
            return(tab);
        }
示例#2
0
        private void Menu_MenuItemClick(object sender, PopupMenu.MenuItemClickEventArgs e)
        {
            switch (e.Item.ItemId)
            {
            /*case Resource.Id.selectionMode:
             * e.Item.SetChecked(
             *  selectSingle = !e.Item.IsChecked);
             * return;*/
            case Resource.Id.logFast:
                bool logfast;
                e.Item.SetChecked(
                    logfast = !e.Item.IsChecked);
                verifyStoragePermissions();
                parser.LogFast(logfast, filePath);
                bluetoothHandler.ChangeFilter(currentTab.include);
                if (logfast)
                {
                    ActionBar.NavigationMode = ActionBarNavigationMode.Standard;
                }
                else
                {
                    ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
                }
                return;

            //case Resource.Id.logSlow:
            //e.Item.SetChecked(
            //selectSingle = !e.Item.IsChecked);
            //return;
            case Resource.Id.debugLog:
                bool l;
                e.Item.SetChecked(
                    l = !e.Item.IsChecked);
                verifyStoragePermissions();
                bluetoothHandler.Log(l, filePath);
                return;

            /*case Resource.Id.hang:
             * e.Item.SetChecked(!e.Item.IsChecked);
             * bluetoothHandler.createHangup=!bluetoothHandler.createHangup;
             * return;*/
            /*case Resource.Id.verbose:
             * e.Item.SetChecked(
             *  bluetoothHandler.verbose = !e.Item.IsChecked);
             * return;*/
            case Resource.Id.metric:
                e.Item.SetChecked(
                    !(convertToImperial = e.Item.IsChecked));
                editor = prefs.Edit();
                editor.PutBoolean("convertToImperial", convertToImperial);
                editor.Commit();
                return;

            case Resource.Id.viewType:
                currentTab.style++;
                if (currentTab.style > 2)
                {
                    currentTab.style = 0;
                }
                gridView1.NumColumns = currentTab.style == 0 ? 1 : currentTab.size;
                gridView1.InvalidateViews();
                SaveTabs();
                return;

            case Resource.Id.bigger:
                if (currentTab.style == 0)
                {
                    currentTab.size++;
                }
                else
                {
                    currentTab.size--;
                }
                if (currentTab.size < 1)
                {
                    currentTab.size = 1;
                }
                gridView1.NumColumns = currentTab.style == 0 ? 1 : currentTab.size;
                SaveTabs();
                return;

            case Resource.Id.smaller:
                if (currentTab.style == 0)
                {
                    currentTab.size--;
                }
                else
                {
                    currentTab.size++;
                }
                if (currentTab.size < 1)
                {
                    currentTab.size = 1;
                }
                gridView1.NumColumns = currentTab.style == 0 ? 1 : currentTab.size;
                SaveTabs();
                return;

            case Resource.Id.bluetoothEnabled:
                bool bt;
                e.Item.SetChecked(
                    bt = !e.Item.IsChecked);
                if (bt)
                {
                    bluetoothHandler.Initialize();
                    //bluetoothHandler.ChangeFilter(new string(parser.tagFilter));
                }
                else
                {
                    bluetoothHandler.Stop();
                }
                return;

            case Resource.Id.resettrip:
                parser.ResetTrip();
                flagNewTrip = true;
                bluetoothHandler.ChangeFilter(currentTab.include);
                //SaveTabs();
                return;

            case Resource.Id.newtrip:
                //parser.LoadTrip(filePath+ "/TripStart 2017-03-02 21-31-36.xml");
                trip = new Trip(false);
                char c = 'A';
                for (int i = 0; i < ActionBar.TabCount; i++)
                {
                    if (ActionBar.GetTabAt(i).Text.Contains("Trip"))
                    {
                        c++;
                    }
                }
                var newTab =
                    CreateTab("Trip " + c, "t", "2", "2");
                flagNewTrip = true;
                ActionBar.SelectTab(newTab.ActionBarTab);
                //SaveTabs();
                return;

            case Resource.Id.newtab:
                PopupMenu menu = new PopupMenu(this, menuIcon);
                menu.Inflate(Resource.Menu.TabsMenu);
                for (int i = 0; i < tabTitle.GetLength(0); i++)
                {
                    if (tabTitle[i, 0] != "Trip")
                    {
                        menu.Menu.Add(tabTitle[i, 0]);
                    }
                }

                menu.MenuItemClick += (s1, arg1) => {
                    if (arg1.Item.TitleFormatted.ToString() == "Blank")
                    {
                        newTab = CreateTab("New", "0", "0", "1");
                        ActionBar.SelectTab(newTab.ActionBarTab);
                    }
                    else
                    {
                        for (int i = 0; i < tabTitle.GetLength(0); i++)
                        {
                            if (tabTitle[i, 0] == arg1.Item.TitleFormatted.ToString())
                            {
                                newTab = CreateTab(tabTitle[i, 0], tabTitle[i, 1], tabTitle[i, 2], tabTitle[i, 3]);
                                ActionBar.SelectTab(newTab.ActionBarTab);
                                break;
                            }
                        }
                    }
                };
                menu.Show();
                SaveTabs();
                return;

            case Resource.Id.deletetab:
                //var pos = tabs.IndexOf(currentTab);
                tabs.Remove(currentTab);
                ActionBar.RemoveTab(currentTab.ActionBarTab);

                /*if (pos >= ActionBar.TabCount)
                 * pos = ActionBar.TabCount-1;
                 * if (pos < 0)
                 * pos = 0;
                 * currentTab = tabs.ElementAtOrDefault(pos);
                 * ActionBar.SelectTab(currentTab.ActionBarTab);*/
                SaveTabs();
                return;

            case Resource.Id.paste:
                currentTab.include.AddRange(
                    from inc in parser.GetAllValues()
                    where clipboard.Any(x => x.name == inc.name)
                    select inc);
                ladapter.items = currentTab.GetItems(parser);
                ladapter.NotifyChange();
                if (bluetoothHandler.active)
                {
                    bluetoothHandler.ChangeFilter(currentTab.include);
                }
                SaveTabs();
                return;

            case Resource.Id.browse:
                //ShowDlg("Logs are stored in\n\n"+filePath);
                Intent          intent = new Intent(Intent.ActionGetContent);
                Android.Net.Uri uri    = Android.Net.Uri.Parse(filePath);
                //intent.PutExtra(Intent.ExtraAllowMultiple,true);
                intent.SetDataAndType(uri, "*/*");
                //StartActivity(Intent.CreateChooser(intent, "Logs"));
                /*Intent intent = new Intent(Intent.ActionOpenDocumentTree);*/
                StartActivityForResult(intent, PICKFILE_REQUEST_CODE);
                return;

            case Resource.Id.device:
                StartActivityForResult(typeof(DeviceListActivity), 1);
                return;

            case Resource.Id.resettabs:
                editor = prefs.Edit();
                editor.Remove("tabs");
                editor.Commit();
                Toast.MakeText(this, "Tabs will be reset on app restart.\nTo undo, edit any tab now", ToastLength.Long).Show();
                return;

            case Resource.Id.resetthrow:
                ladapter.limits.Clear();
                foreach (var item in ladapter.items)
                {
                    item.UpdateLimits(item.GetValue(false));
                }
                return;

            case Resource.Id.help:
                uri    = Android.Net.Uri.Parse("https://sites.google.com/view/scanmytesla/changelog");
                intent = new Intent(Intent.ActionView, uri);
                StartActivity(intent);
                return;
            }
        }
示例#3
0
        private void LoadTabs()
        {
            try {
                string json = prefs.GetString("tabs", "");

                tabs = Tab.DeSerialize(json);

                foreach (var tab in tabs)
                {
                    if (tab.name == "All")
                    {
                        CreateTab("All", "", "0", "1", tab);
                        tab.items = new List <ListElement>();
                    }
                    else
                    {
                        ActionBar.Tab aTab = ActionBar.NewTab();
                        aTab.SetText(tab.name);
                        tab.ActionBarTab = aTab;

                        Value[] temp = new Value[tab.include.Count];
                        tab.include.CopyTo(temp);
                        tab.include.Clear();
                        foreach (var t in temp)
                        {
                            try {
                                tab.items = new List <ListElement>();
                                tab.include.Add(
                                    parser
                                    .GetAllValues()
                                    .Where(x => x.name == t.name)
                                    .First());
                            }
                            catch (Exception) { }
                        }
                        ;

                        if (tab.name.Contains("Trip"))
                        {
                            trip = tab.trip == null ? tab.trip = new Trip(false) : tab.trip;
                        }

                        aTab.TabSelected += (sender, args) => {
                            currentTab = tab;
                            if (bluetoothHandler.active)
                            {
                                bluetoothHandler.ChangeFilter(currentTab.include);
                            }
                            ladapter.items = currentTab.GetItems(parser);
                            ladapter.items.Any(x => x.selected = false);
                            gridView1.NumColumns = currentTab.style == 0 ? 1 : currentTab.size;
                            gridView1.Invalidate();
                            ladapter.NotifyChange();
                            if (!starting)
                            {
                                editor = prefs.Edit();
                                editor.PutString("currentTab", currentTab.name);
                                editor.Commit();
                            }
                        };
                        ActionBar.AddTab(aTab);
                    }
                }
            }
            catch (Exception e) { Console.WriteLine(e.ToString()); }
        }