Example #1
0
        protected override void OnElementChanged(ElementChangedEventArgs <SearchBar> e)
        {
            base.OnElementChanged(e);
            if (Control != null)
            {
                SearchView searchView = Control;
                searchView.Iconified = false;
                searchView.SetIconifiedByDefault(false);

                EditText editText = Control.GetChildrenOfType <EditText>().First();

                editText.SetHighlightColor(Color.Accent.ToAndroid());

                if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Q)
                {
                    TrySetCursorPointerColorNew(editText);
                    UpdateSearchButtonColorNew();
                    UpdateCancelButtonColorNew();
                }
                else
                {
                    TrySetCursorPointerColor(editText);
                    UpdateSearchButtonColor();
                    UpdateCancelButtonColor();
                }
            }
        }
Example #2
0
        private void searchByVoice(object sender, EventArgs e)
        {
            MainActivity act        = (MainActivity)this.Activity;
            SearchView   searchView = (SearchView)act.FindViewById(Resource.Id.searchView1);

            //If coming from the text search focus, get rid of it.
            if (flagSearch)
            {
                searchView.Focusable = false;
                searchView.SetIconifiedByDefault(true);
                searchView.OnActionViewCollapsed();
            }

            Intent intent = new Intent(RecognizerIntent.ActionRecognizeSpeech);

            try
            {
                intent.PutExtra(RecognizerIntent.ActionRecognizeSpeech, "en-US");
                intent.PutExtra(RecognizerIntent.ExtraLanguageModel, RecognizerIntent.LanguageModelFreeForm);
                intent.PutExtra(RecognizerIntent.ExtraLanguage, LocaleList.Default);
                intent.PutExtra(RecognizerIntent.ExtraSpeechInputCompleteSilenceLengthMillis, 8000);

                act.StartActivityForResult(intent, 100);
            }catch (ActivityNotFoundException)
            {
                Toast t = Toast.MakeText(this.Activity, "Your device doesn't support Speech to Text", ToastLength.Short);
                t.Show();
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            ThreadPool.QueueUserWorkItem(o => LoadUser());
            SetContentView(Resource.Layout.activity_search);
            Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(toolbar);

            DrawerLayout          drawer = FindViewById <DrawerLayout>(Resource.Id.drawer_layout);
            ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, Resource.String.navigation_drawer_open, Resource.String.navigation_drawer_close);

            drawer.AddDrawerListener(toggle);
            toggle.SyncState();

            NavigationView navigationView = FindViewById <NavigationView>(Resource.Id.nav_view);

            navigationView.SetNavigationItemSelectedListener(this);

            _lv = FindViewById <ListView>(Resource.Id.lvSearched);

            SearchView searchButton = FindViewById <SearchView>(Resource.Id.searchButton);

            searchButton.SetQueryHint("Enter your query");
            searchButton.SetIconifiedByDefault(false);
            searchButton.QueryTextSubmit += (sender, e) =>
            {
                ThreadPool.QueueUserWorkItem(o => GetGalleryImagesAsync(searchButton.Query));
            };
        }
Example #4
0
        public override Android.Views.View GetSampleContent(Android.Content.Context context)
        {
            LinearLayout linear = new LinearLayout(context)
            {
                Orientation = Orientation.Vertical
            };

            listView = new ListView(context);
            listView.FastScrollEnabled = true;
            viewModel                       = new ContatsViewModel();
            sfDataSource                    = new DataSource();
            sfDataSource.Source             = viewModel.ContactsList;
            sfDataSource.LiveDataUpdateMode = LiveDataUpdateMode.AllowDataShaping;
            sfDataSource.SortDescriptors.Add(new SortDescriptor("ContactName", Syncfusion.DataSource.ListSortDirection.Ascending));
            listView.Adapter = new ContactsAdapter(sfDataSource, context);
            filterText       = new SearchView(context);
            filterText.SetIconifiedByDefault(false);
            filterText.SetPadding(0, 0, 0, (int)(10 * context.Resources.DisplayMetrics.Density));
            filterText.SetQueryHint("Search contact");
            filterText.QueryTextChange += OnFilterTextChanged;
            linear.AddView(new LinearLayout(context)
            {
                Focusable = true, FocusableInTouchMode = true
            }, 0, 0);
            linear.AddView(filterText);
            linear.AddView(listView);
            return(linear);
        }
Example #5
0
 private void setupSearchView()
 {
     mySearchView.SetIconifiedByDefault(false);
     mySearchView.SetOnQueryTextListener(this);
     mySearchView.SubmitButtonEnabled = true;
     mySearchView.SetQueryHint("Search");
 }
        public override Android.Views.View GetSampleContent(Android.Content.Context context)
        {
            LinearLayout linear = new LinearLayout(context);

            linear.Orientation = Orientation.Vertical;
            dataSource         = new DataSource();
            viewModel          = new DataSourceGettingStartedViewModel(context);
            viewModel.SetRowstoGenerate(100);
            listView = new ListView(context);

            dataSource.Source             = viewModel.BookInfo;
            dataSource.LiveDataUpdateMode = Syncfusion.DataSource.LiveDataUpdateMode.AllowDataShaping;
            dataSource.SortDescriptors.Add(new SortDescriptor()
            {
                Direction    = Syncfusion.DataSource.ListSortDirection.Descending,
                PropertyName = "BookID",
            });

            listView.Adapter = new CustomAdapter(dataSource, context);
            filterText       = new SearchView(context);
            filterText.SetIconifiedByDefault(false);
            filterText.SetPadding(0, 0, 0, (int)(10 * context.Resources.DisplayMetrics.Density));
            this.filterText.KeyPress += FilterText_KeyPress;
            filterText.SetQueryHint("Enter the text to filter");
            filterText.QueryTextChange += OnFilterTextChanged;
            viewModel.Filtertextchanged = OnFilterChanged;
            linear.AddView(new LinearLayout(context)
            {
                Focusable = true, FocusableInTouchMode = true
            }, 0, 0);
            linear.AddView(filterText);
            linear.AddView(listView);
            return(linear);
        }
Example #7
0
        void OnSearchLayoutSelected(object sender, EventArgs e)
        {
            _searchView.SetIconifiedByDefault(false);

            _searchView.RequestFocusFromTouch();

            _keyboardService.ShowKeyboard(_searchView);
        }
        void SetupSearchInput(SearchView searchView)
        {
            var searchManager = Activity.GetSystemService(Context.SearchService).JavaCast <SearchManager> ();

            searchView.SetIconifiedByDefault(false);
            var searchInfo = searchManager.GetSearchableInfo(Activity.ComponentName);

            searchView.SetSearchableInfo(searchInfo);
        }
Example #9
0
        void SetUpScreen()
        {
            _searchLayout.Click += OnSearchLayoutSelected;

            _searchView.QueryTextSubmit += OnQuerySubmit;

            _searchView.QueryTextChange += OnQueryTextChanged;

            _searchView.Focusable = true;

            _searchView.RequestFocusFromTouch();

            _searchView.ClearFocus();

            _searchView.SetIconifiedByDefault(false);

            _searchView.SetQueryHint(GetString(Resource.String.HomePageSearchBarHint));

            PersonalizeSearchView();
        }
Example #10
0
        public override bool OnCreateOptionsMenu(IMenu menu)
        {
            MenuInflater.Inflate(Resource.Menu.main_menu, menu);

            var item = menu.FindItem(Resource.Id.action_search);

            _searchView = item.ActionView as Android.Support.V7.Widget.SearchView;
            _searchView.SetOnQueryTextListener(this);
            item.SetOnActionExpandListener(this);
            _searchView.SetIconifiedByDefault(false);

            return(base.OnCreateOptionsMenu(menu));
        }
Example #11
0
        protected override void OnElementChanged(ElementChangedEventArgs <SearchBar> e)
        {
            base.OnElementChanged(e);

            SearchView searchView = Control;

            searchView.Iconified = true;
            searchView.SetIconifiedByDefault(false);

            int searchIconId = Context.Resources.GetIdentifier("android:id/search_mag_icon", null, null);
            var icon         = searchView.FindViewById(searchIconId);

            icon.RemoveFromParent();
        }
Example #12
0
        private void searchByText(object sender, EventArgs e)
        {
            //change focus off button
            Button mButton = (Button)sender;

            mButton.Focusable = false;

            //Get activity and the searchView. Set Listener on it
            MainActivity act     = (MainActivity)this.Activity;
            SearchView   searchV = (SearchView)act.FindViewById(Resource.Id.searchView1);

            //loses focus on search view if it already given focus before ((allows for backout without querying and pressing the button again))
            if (flagSearch)
            {
                searchV.Focusable = false;
                searchV.SetIconifiedByDefault(true);
                searchV.OnActionViewCollapsed();
            }

            searchV.RequestFocus();
            searchV.SetIconifiedByDefault(false);
            searchV.OnActionViewExpanded();
            flagSearch = true;
        }
Example #13
0
        protected override void OnElementChanged(ElementChangedEventArgs <SearchBar> e)
        {
            base.OnElementChanged(e);

            // Get native control (background set in shared code, but can use SetBackgroundColor here)
            SearchView searchView = (base.Control as SearchView);

            searchView.SetInputType(InputTypes.ClassText | InputTypes.TextVariationNormal);

            //change icon search
            searchView.SetIconifiedByDefault(false);
            int searchIconId = Context.Resources.GetIdentifier("android:id/search_mag_icon", null, null);
            var icon         = searchView.FindViewById(searchIconId);

            icon.SetBackgroundColor(Android.Graphics.Color.White);
            (icon as ImageView).SetImageResource(Resource.Drawable.ios23);

            //change icon close
            int searchViewCloseButtonId = Control.Resources.GetIdentifier("android:id/search_close_btn", null, null);
            var closeIcon = searchView.FindViewById(searchViewCloseButtonId);

            (closeIcon as ImageView).SetImageResource(Resource.Drawable.close);

            // Access search textview within control
            int      textViewId = searchView.Context.Resources.GetIdentifier("android:id/search_src_text", null, null);
            EditText textView   = (searchView.FindViewById(textViewId) as EditText);

            textView.SetTextColor(Android.Graphics.Color.Black);
            textView.SetHintTextColor(Android.Graphics.Color.Rgb(180, 180, 180));
            textView.TextAlignment = Android.Views.TextAlignment.TextStart;

            //add borders to the search bar
            if (textView != null)
            {
                var shape = new ShapeDrawable(new RectShape());
                shape.Paint.Color       = Android.Graphics.Color.Transparent;
                shape.Paint.StrokeWidth = 0;
                shape.Paint.SetStyle(Paint.Style.Stroke);
                textView.Background = shape;
            }

            var gradient = new GradientDrawable();

            gradient.SetCornerRadius(5.0f);
            gradient.SetStroke((int)this.Context.ToPixels(1.0f), Android.Graphics.Color.Rgb(169, 169, 169));

            this.Control.SetBackground(gradient);
        }
        protected override void OnElementChanged(ElementChangedEventArgs <SearchBar> args)
        {
            base.OnElementChanged(args);

            // Get native control (background set in shared code, but can use SetBackgroundColor here)
            SearchView searchView = (base.Control as SearchView);

            searchView.SetInputType(InputTypes.ClassText | InputTypes.TextVariationNormal);
            searchView.Iconified = true;
            searchView.SetIconifiedByDefault(false);

            int searchIconId = Context.Resources.GetIdentifier("android:id/search_mag_icon", null, null);
            var icon         = searchView.FindViewById(searchIconId);

            (icon as ImageView).SetImageResource(Resource.Drawable.ic_search_white_24dp);
        }
Example #15
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            //Loads the assets of the application
            assets = this.Assets;

            //Get the list of currencies
            currencies           = APIMethods.GetMarkets();
            currenciesStringList = new List <string>();

            foreach (var currency in currencies)
            {
                currenciesStringList.Add(currency.MarketName);
            }

            Constants.ApiKey    = LoginData.APIKey;
            Constants.SecretKey = LoginData.SecretKey;

            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            //Set the toolbar
            var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar);

            toolbar.SetTitleTextColor(Android.Graphics.Color.White);
            SetActionBar(toolbar);
            ActionBar.Title = "Bittrex";

            //Initialise the adapter and search view
            _adapter = new SearchableAdapter(this, currenciesStringList);

            _listView         = this.FindViewById <ListView>(Resource.Id.listView);
            _listView.Adapter = _adapter;

            _listView.ItemClick += _listView_ItemClick;

            var searchView = (SearchView)FindViewById(Resource.Id.searchView);

            _searchView = searchView.JavaCast <SearchView>();

            _searchView.SetIconifiedByDefault(false);
            _searchView.SetBackgroundColor(Android.Graphics.Color.White);
            _searchView.SetQueryHint("Search currencies");

            _searchView.QueryTextChange += (s, e) => _adapter.Filter.InvokeFilter(new Java.Lang.String(e.NewText));
        }
Example #16
0
        protected override void OnElementChanged(ElementChangedEventArgs <SearchBar> e)
        {
            base.OnElementChanged(e);
            if (Control != null)
            {
                SearchView searchView = Control;
                searchView.Iconified = false;
                searchView.SetIconifiedByDefault(false);

                EditText editText = Control.GetChildrenOfType <EditText>().First();

                SetCursorColor(editText);
                TrySetCursorPointerColor(editText);

                UpdateSearchButtonColor();
                UpdateCancelButtonColor();
            }
        }
Example #17
0
        public void SearchType(View view)
        {
            KeyEvent    enter      = new KeyEvent(KeyEventActions.Down, Keycode.Enter);
            SearchView  searchView = FindViewById <SearchView>(Resource.Id.searchView1);
            RadioButton radio      = ((RadioButton)view);
            TextView    text       = FindViewById <TextView>(Resource.Id.searchTVFAB);

            if (radio == FindViewById <RadioButton>(Resource.Id.topicRadio))
            {
                if (radio.Checked)
                {
                    searchView.Enabled = true;

                    searchView.SetImeOptions(Android.Views.InputMethods.ImeAction.Go);
                    searchView.SetInputType(Android.Text.InputTypes.ClassText);
                    searchView.QueryTextSubmit += Search_QueryTextSubmit;
                    searchView.SetQueryHint("Search By topic");
                    text.Text = GetString(Resource.String.Search);
                }
            }
            //Chapter/Question Number Search
            else if (radio == FindViewById <RadioButton>(Resource.Id.chapterRadio))
            {
                if (radio.Checked)
                {
                    searchView.Enabled = true;
                    searchView.SetInputType(Android.Text.InputTypes.ClassNumber);
                    searchView.SetQueryHint("Search By Number...");
                    text.Text = GetString(Resource.String.Search);
                }
            }
            else if (radio == FindViewById <RadioButton>(Resource.Id.viewAllRadio))
            {
                text.Text = GetString(Resource.String.View_Button);
                if (!creedOpen)
                {
                    searchView.SetIconifiedByDefault(true);
                    searchView.Enabled = false;
                }
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.CustomerSearch);

            user = Serializador.LoadFromXMLString <Usuario>(PreferenceManager.GetDefaultSharedPreferences(this).GetString("user", ""));

            listView            = FindViewById <ListView>(Resource.Id.listaClientes);
            listView.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) =>
            {
                var pessoa = arrayPessoas[e.Position];

                if (pessoa.Ativo != 'Y')
                {
                    AlertDialog.Builder alert = new AlertDialog.Builder(this);
                    alert.SetTitle("Aviso");
                    alert.SetMessage("Este cliente encontra-se inativo!");
                    alert.SetPositiveButton("Fechar", (s, v) => { });
                    alert.Show();
                    return;
                }

                SendPerson(pessoa.Codigo);
            };

            searchView = FindViewById <SearchView>(Resource.Id.searchView);
            searchView.SetIconifiedByDefault(false);

            searchView.QueryTextSubmit += (object sender, SearchView.QueryTextSubmitEventArgs e) =>
            {
                string query = e.Query;

                if (string.IsNullOrEmpty(query))
                {
                    return;
                }

                Search(query);
            };
        }
Example #19
0
        private void SetData(View rootView)
        {
            SearchManager searchManager = (SearchManager)Activity.GetSystemService(Android.Content.Context.SearchService);

            _searchView = rootView.FindViewById <SearchView>(Resource.Id.search);
            _searchView.SetSearchableInfo(searchManager.GetSearchableInfo(Activity.ComponentName));

            _searchView.SetIconifiedByDefault(false);
            _searchView.SetOnQueryTextListener(this);
            _searchView.SetOnCloseListener(this);
            _searchView.ClearFocus();

            Android.Views.InputMethods.InputMethodManager mgr = (Android.Views.InputMethods.InputMethodManager)Activity.GetSystemService(Android.Content.Context.InputMethodService);
            mgr.HideSoftInputFromWindow(_searchView.WindowToken, 0);
            SimpleSelectorItem[] items = (ParcableTest.Dialogs.SimpleSelectorItem[])Arguments.GetParcelableArray(ITEMS);

            _lvSelector = (ListView)rootView.FindViewById(Resource.Id.lvSelector);
            SimpleSelectorListAdapter adapter = new SimpleSelectorListAdapter(Activity, items.ToList());

            _lvSelector.Adapter = adapter;
        }
Example #20
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Zoeken);
            ActionBar.Hide();
            m_afvalproduct = MainActivity.m_afvalproduct;

            _Menu = FindViewById <ImageButton>(Resource.Id.Menu);
            _lv   = FindViewById <ListView>(Resource.Id.lv);
            _sv   = FindViewById <SearchView>(Resource.Id.sv);
            _sv.SetIconifiedByDefault(false);
            _sv.ClearFocus();
            _sv.SetQueryHint("Glas, Plastic, Papier, Afval");

            _adapter    = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, DataToList());
            _lv.Adapter = _adapter;

            _sv.QueryTextChange += _sv_QueryTextChange;
            _lv.ItemClick       += _lv_ItemClick;
            _Menu.Click         += _Menu_Click;
        }
Example #21
0
        public override Android.Views.View GetSampleContent(Android.Content.Context context)
        {
            LinearLayout linear = new LinearLayout(context)
            {
                Orientation = Orientation.Vertical
            };

            listView                        = new ListView(context);
            viewModel                       = new ContatsViewModel();
            sfDataSource                    = new DataSource();
            sfDataSource.Source             = viewModel.ContactsList;
            sfDataSource.LiveDataUpdateMode = LiveDataUpdateMode.AllowDataShaping;
            listView.Adapter                = new ContactsAdapter(sfDataSource, context);
            sfDataSource.SortDescriptors.Add(new SortDescriptor("ContactName"));
            sfDataSource.GroupDescriptors.Add(new GroupDescriptor()
            {
                PropertyName = "ContactName",
                KeySelector  = (object obj1) =>
                {
                    var item = (obj1 as Contacts);
                    return(item.ContactName[0].ToString());
                }
            });
            filterText = new SearchView(context);
            filterText.SetIconifiedByDefault(false);
            filterText.SetPadding(0, 0, 0, (int)(10 * context.Resources.DisplayMetrics.Density));
            filterText.SetQueryHint("Search contact");
            filterText.QueryTextChange += OnFilterTextChanged;
            linear.AddView(new LinearLayout(context)
            {
                Focusable = true, FocusableInTouchMode = true
            }, 0, 0);
            linear.AddView(filterText);
            linear.AddView(listView);
            return(linear);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            user = Serializador.LoadFromXMLString <Usuario>(PreferenceManager.GetDefaultSharedPreferences(this).GetString("user", ""));
            shop = Serializador.LoadFromXMLString <Loja>(PreferenceManager.GetDefaultSharedPreferences(this).GetString("shop", ""));

            MobileBarcodeScanner.Initialize(Application);
            SetContentView(Resource.Layout.ProductSearch);

            Toolbar toolbar = FindViewById <Toolbar>(Resource.Id.toolbar);

            toolbar.InflateMenu(Resource.Menu.product_search_options_menu);
            toolbar.FindViewById <TextView>(Resource.Id.scan).SetTextColor(Android.Graphics.Color.White);

            toolbar.MenuItemClick += (sender, e) =>
            {
                switch (e.Item.ItemId)
                {
                case Resource.Id.scan:
                    Scan();
                    break;
                }
            };

            listView            = FindViewById <ListView>(Resource.Id.listaProdutos);
            listView.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) =>
            {
                var produto = arrayProdutos[e.Position];

                if (produto.Ativo != 'Y')
                {
                    AlertDialog.Builder alert = new AlertDialog.Builder(this);
                    alert.SetTitle("Aviso");
                    alert.SetMessage("Este produto encontra-se inativo!");
                    alert.SetPositiveButton("Fechar", (s, v) => { });
                    alert.Show();
                    return;
                }

                var intent = new Intent(this, typeof(ItemActivity));
                intent.PutExtra("productCode", produto.CdProduto);
                intent.PutExtra("shopCode", shop.ERP.Codigo);
                intent.PutExtra("action", "new");
                StartActivity(intent);
            };

            searchView = FindViewById <SearchView>(Resource.Id.searchView);
            searchView.SetIconifiedByDefault(false);

            searchView.QueryTextSubmit += (object sender, SearchView.QueryTextSubmitEventArgs e) =>
            {
                string query = e.Query;

                if (string.IsNullOrEmpty(query))
                {
                    return;
                }

                Search(query);
            };
        }
Example #23
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            //OnCreate takes a Bundle parameter, which is a dictionary for storing and passing state information
            //and objects between activities If the bundle is not null, this indicates the activity is restarting
            //and it should restore its state from the previous instance. "https:/docs.microsoft.com/en-us/xamarin/android/app-fundamentals/activity-lifecycle/"
            base.OnCreateView(inflater, container, savedInstanceState);
            //Once on create has finished, android will call OnStart which will start the activity

            //sets the layout of the main menu to the ACFIPage.axml file which is located in Resources/layout/
            View view = inflater.Inflate(Resource.Layout.ACFIPage, container, false);

            //setup lists for acfi funding data
            dataItems    = new List <ACFIFunding>();
            displayItems = new List <ACFIFunding>();
            searchItems  = new List <ACFIFunding>();

            //setup custom list adapter, more info found in ACFIViewAdapter.cs
            dataList = view.FindViewById <ListView>(Resource.Id.DataList);
            adapter  = new ACFIViewAdapter(this.Context, dataItems);

            //Display the number of data items at the bottom of the page
            NumItems = view.FindViewById <TextView>(Resource.Id.txtNumData);

            //AVG income per resident monthly textview
            AvgIncome = view.FindViewById <TextView>(Resource.Id.ACFIAvgValue);

            //setup buttons at the top of the page which are used to sort the list based on the button pushed
            Button ResidentBtn       = view.FindViewById <Button>(Resource.Id.ResidentIDTextACFI);
            Button ScoreBtn          = view.FindViewById <Button>(Resource.Id.ScoreTextACFI);
            Button IncomeBtn         = view.FindViewById <Button>(Resource.Id.IncomeTextACFI);
            Button ExpirationDateBtn = view.FindViewById <Button>(Resource.Id.ExpirationDateTextACFI);

            //setup Spinner to sort facilities
            Spinner spinner = view.FindViewById <Spinner>(Resource.Id.FacilitySpinner);

            spinner.Clickable     = false;
            spinner.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(Spinner_ItemSelected);
            var SpinnerAdapter = ArrayAdapter.CreateFromResource(view.Context, Resource.Array.FacilityArray, Android.Resource.Layout.SimpleSpinnerItem);//array found in Resources/values/

            SpinnerAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            spinner.Adapter = SpinnerAdapter;

            //setup Month Spinner for the AVG income per resident monthly widget
            Spinner MonthSpinner = view.FindViewById <Spinner>(Resource.Id.MonthSpinner);

            MonthSpinner.Clickable     = false;
            MonthSpinner.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(Spinner_MonthItemSelected);
            var MonthSpinnerAdapter = ArrayAdapter.CreateFromResource(view.Context, Resource.Array.MonthArray, Android.Resource.Layout.SimpleSpinnerItem);

            MonthSpinnerAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            MonthSpinner.Adapter = MonthSpinnerAdapter;

            //create new WebClient class object which can provide methods to push and recieve data from an online resource via a url
            client = new WebClient();
            //set the url to push and pull data from, via the a Uri class object
            //the online resource is a php file hosted on heroku, these php files read write and pull database tables
            url = new Uri("https://capstonephpcode198.herokuapp.com/PullData.php");

            //setup toast message which is pop up message which informs the user that data is being pulled
            toastMessage = Toast.MakeText(this.Context, "Fetching data", ToastLength.Long);

            //setup graph button
            Button GraphButton = view.FindViewById <Button>(Resource.Id.GraphButton);

            GraphButton.Enabled = false;//disabled untill data is pulled
            GraphButton.Click  += delegate {
                var       transaction = ChildFragmentManager.BeginTransaction();
                ACFIGraph info        = new ACFIGraph(displayItems);//displayItems to use all data
                info.Show(transaction, "dialog fragment");
            };

            //setup search bar
            SearchView SearchItems = view.FindViewById <SearchView>(Resource.Id.searchData);
            //an X apears next the search upon a submitted query, this X closes the current search, SearchCloseBtn button variable is associated with this
            //find the resource id's associated with the search and close buttons for the search bar widget
            int searchBtnID    = SearchItems.Context.Resources.GetIdentifier("android:id/search_button", null, null);
            int closeBtnID     = SearchItems.Context.Resources.GetIdentifier("android:id/search_close_btn", null, null);
            var SearchOpenBtn  = view.FindViewById <ImageView>(searchBtnID);
            var SearchCloseBtn = view.FindViewById <ImageView>(closeBtnID);

            SearchItems.SetIconifiedByDefault(false); //shows hint
            SearchItems.Enabled          = false;     //disable untill data is pulled
            SearchOpenBtn.Enabled        = false;
            SearchItems.QueryTextSubmit += delegate {
                //this search bar allows the user to search via resident id
                string searchID = SearchItems.Query;
                foreach (ACFIFunding item in dataItems)
                {
                    //use searchItems list to hold all items while items get removed from the dataItems list if they don't match the search credentials
                    if (!searchItems.Contains(item))
                    {
                        searchItems.Add(item);
                    }
                }
                //if search credentials match or don't match, remove or add items from dataItems list
                foreach (ACFIFunding item in searchItems)
                {
                    if (dataItems.Contains(item) && (!String.Equals(item.GetResidentID().ToString(), searchID)))
                    {
                        dataItems.Remove(item);
                    }
                    else if (!dataItems.Contains(item) && (String.Equals(item.GetResidentID().ToString(), searchID)))
                    {
                        dataItems.Add(item);
                    }
                }
                SearchItems.ClearFocus();
                adapter.NotifyDataSetChanged();
            };
            //when the search bar close button is pressed, add all items from searchItems into dataItems
            SearchCloseBtn.Click += delegate {
                foreach (ACFIFunding item in searchItems)
                {
                    if (!dataItems.Contains(item))
                    {
                        dataItems.Add(item);
                    }
                }
                SearchItems.ClearFocus();
                SearchItems.SetQuery(String.Empty, false);
                adapter.NotifyDataSetChanged();
            };

            //setup progress bar for data pulling
            ProgressBar ClientProgress = view.FindViewById <ProgressBar>(Resource.Id.ClientProgress);

            //show progress percentage on the bar
            client.UploadProgressChanged += delegate(object sender, UploadProgressChangedEventArgs e) {
                ClientProgress.Progress += e.ProgressPercentage;
            };

            //refresh button pulls data from database
            Button RefreshBtn = view.FindViewById <Button>(Resource.Id.RefreshButton);

            RefreshBtn.Click += delegate {
                RefreshBtn.SetBackgroundResource(Resource.Drawable.RefreshButtonIconClicked); //change refresh icon colour to lighter shade of green
                toastMessage.Show();                                                          //show toast message
                spinner.SetSelection(0);
                //clear lists, to make way for updated data
                dataItems.Clear();
                displayItems.Clear();
                spinner.Clickable = false;

                NameValueCollection values = new NameValueCollection();
                values.Add("Type", "ACFI");
                //call php file and use UploadValuesAsync with the value of Type=ACFI so the php file knows to pull ACFI data
                client.UploadValuesAsync(url, values);
            };

            client.UploadValuesCompleted += delegate(object sender, UploadValuesCompletedEventArgs e) {
                Activity.RunOnUiThread(() => {
                    string json           = Encoding.UTF8.GetString(e.Result);
                    dataItems             = JsonConvert.DeserializeObject <List <ACFIFunding> >(json);//use json to create a list of data objects from the output of the php file
                    int[] residentIDArray = new int[dataItems.Count];
                    int count             = 0;
                    //put all resident id values into an array
                    foreach (ACFIFunding item in dataItems)
                    {
                        residentIDArray[count] = item.GetResidentID();
                        count++;
                        displayItems.Add(item);//display items holds all of the data objects for safe keeping, for when dataItems objects get removed
                    }
                    //get distinct resident id values in its own array
                    var distinctResidentIDvals = residentIDArray.Distinct();
                    bool isGreen = false;
                    bool isRed   = false;
                    decimal sum  = 0;
                    //foreach distinct resident id value check if the rows for a resident id should be green, yellow or red, this is beacuse some resident id's correspond with multiple rows
                    foreach (int ID in distinctResidentIDvals)
                    {
                        sum = 0;
                        foreach (ACFIFunding item in dataItems.Where(x => x.GetResidentID() == ID))
                        {
                            sum = sum + item.GetIncome();
                        }
                        //if the sum of all acfi income for a resident is above $200
                        if (sum > 200)
                        {
                            isGreen = true;
                            isRed   = false;
                        }
                        else if (sum < 150)
                        { //if the sum of all acfi income for a resident is below $150
                            isGreen = false;
                            isRed   = true;
                        }
                        else    //yellow
                        {
                            isGreen = false;
                            isRed   = false;
                        }
                        foreach (ACFIFunding item in dataItems.Where(x => x.GetResidentID() == ID))
                        {
                            item.SetGreen(isGreen);
                            item.SetRed(isRed);
                        }
                    }
                    adapter          = new ACFIViewAdapter(this.Context, dataItems);//setup adapter
                    NumItems.Text    = dataItems.Count.ToString();
                    dataList.Adapter = adapter;
                    RefreshBtn.SetBackgroundResource(Resource.Drawable.RefreshButtonIcon);
                    spinner.Clickable     = true;
                    GraphButton.Enabled   = true;
                    SearchItems.Enabled   = true;
                    SearchOpenBtn.Enabled = true;
                    toastMessage.Cancel();
                    searchItems.Clear();
                    adapter.NotifyDataSetChanged();
                });
            };

            //sort the items based on residentID
            ResidentBtn.Click += delegate {
                if (clickNumResident == 0)
                {
                    dataItems.Sort(delegate(ACFIFunding one, ACFIFunding two) {
                        return(one.GetResidentID().CompareTo(two.GetResidentID()));
                    });
                    clickNumResident++;
                    clickNumScore       = 0;
                    clickNumIncome      = 0;
                    clickExpirationDate = 0;
                    //reverse list if clicked a second time in a row
                }
                else
                {
                    dataItems.Reverse();
                    clickNumResident = 0;
                }
                adapter.NotifyDataSetChanged();
            };

            //sort the items based on score
            ScoreBtn.Click += delegate {
                if (clickNumScore == 0)
                {
                    dataItems.Sort(delegate(ACFIFunding one, ACFIFunding two) {
                        return(one.GetACFIScore().CompareTo(two.GetACFIScore()));
                    });
                    clickNumScore++;
                    clickNumResident    = 0;
                    clickNumIncome      = 0;
                    clickExpirationDate = 0;
                    //reverse list if clicked a second time in a row
                }
                else
                {
                    dataItems.Reverse();
                    clickNumScore = 0;
                }
                adapter.NotifyDataSetChanged();
            };

            //sort the items based on income
            IncomeBtn.Click += delegate {
                if (clickNumIncome == 0)
                {
                    dataItems.Sort(delegate(ACFIFunding one, ACFIFunding two) {
                        return(one.GetIncome().CompareTo(two.GetIncome()));
                    });
                    clickNumIncome++;
                    clickNumResident    = 0;
                    clickNumScore       = 0;
                    clickExpirationDate = 0;
                    //reverse list if clicked a second time in a row
                }
                else
                {
                    dataItems.Reverse();
                    clickNumIncome = 0;
                }
                adapter.NotifyDataSetChanged();
            };

            //sport the items based on expiration date
            ExpirationDateBtn.Click += delegate {
                if (clickExpirationDate == 0)
                {
                    dataItems.Sort(delegate(ACFIFunding one, ACFIFunding two) {
                        return(DateTime.Compare(one.GetExpirationDate(), two.GetExpirationDate()));
                    });
                    clickExpirationDate++;
                    clickNumResident = 0;
                    clickNumScore    = 0;
                    clickNumIncome   = 0;
                    //reverse list if clicked a second time in a row
                }
                else
                {
                    dataItems.Reverse();
                    clickExpirationDate = 0;
                }
                adapter.NotifyDataSetChanged();
            };

            return(view);
        }
Example #24
0
        private async void submitQueryListener(object sender, SearchView.QueryTextSubmitEventArgs e)
        {
            MainActivity act        = (MainActivity)this.Activity;
            SearchView   searchView = (SearchView)act.FindViewById(Resource.Id.searchView1);
            string       input      = e.Query;

            searchView.SetIconifiedByDefault(true);
            searchView.OnActionViewCollapsed();
            searchView.Focusable = false;

            //Ping database by name
            string data = GetData();

            JArray        jsonArray    = JArray.Parse(data);
            List <string> searched_Loc = new List <string>();
            List <string> similar_Loc  = new List <string>();

            string debugMe    = "";
            string tempinput  = input;
            string inputBlock = tempinput;

            tempinput = RemoveSpecialCharacters(tempinput);
            tempinput = tempinput.Replace(" ", System.String.Empty);

            AddressLocator        tempAddress;
            List <AddressLocator> mAddresses = new List <AddressLocator>();

            for (int i = 0; i < jsonArray.Count; i++)
            {
                JToken json = jsonArray[i];
                string temp = (string)json["name"];
                temp = RemoveSpecialCharacters(temp);
                temp = temp.Replace(" ", System.String.Empty);
                if (((string)json["name"]).Equals(input, StringComparison.InvariantCultureIgnoreCase) || temp.Equals(tempinput, StringComparison.InvariantCultureIgnoreCase))
                {
                    //Location stuff - make sure user location permissions were give
                    if (act.CheckSelfPermission(Android.Manifest.Permission.AccessCoarseLocation) == (int)Android.Content.PM.Permission.Granted)
                    {
                        Geocoder        coder   = new Geocoder(act);
                        IList <Address> address = new List <Address>();


                        address = coder.GetFromLocationName(((string)json["street"]) + " " + ((string)json["city"]) + " " + ((string)json["state"]), 5);

                        float lon = (float)address.ElementAt(0).Longitude;
                        float lat = (float)address.ElementAt(0).Latitude;

                        tempAddress = new AddressLocator((string)json["name"], ((string)json["street"]) + " " + ((string)json["city"]) + " " + ((string)json["state"]), lon, lat);
                        mAddresses.Add(tempAddress);


                        userLocationObtained = true;
                    }
                    else // if not, grab list like before.
                    {
                        searched_Loc.Add(((string)json["name"]) + ": " + ((string)json["street"]) + " " + ((string)json["city"]) + " " + ((string)json["state"]));
                    }
                }
            }

            if (userLocationObtained)
            {
                //calculate distances
                CalculateAddressDistance(mAddresses);
                //sort distances
                mAddresses.Sort();

                for (int x = 0; x < mAddresses.Count; x++)
                {
                    searched_Loc.Add(mAddresses.ElementAt(x).Name + ": " + mAddresses.ElementAt(x).Address + " (" + mAddresses.ElementAt(x).Distance.ToString("n2") + " miles)");
                }
            }

            for (int j = 0; j < searched_Loc.Count; j++)
            {
                debugMe += searched_Loc[j];
                debugMe += "\n";
            }

            if (searched_Loc.Count == 0)
            {
                for (int i = 0; i < jsonArray.Count; i++)
                {
                    JToken json      = jsonArray[i];
                    bool   wordMatch = false;
                    string temp      = (string)json["name"];

                    string[] outputBlock = temp.Split(" ");

                    temp = RemoveSpecialCharacters(temp);
                    temp = temp.Replace(" ", System.String.Empty);

                    wordMatch = InputsMatch(inputBlock.ToLower(), outputBlock);

                    if ((tempinput.StartsWith(temp.Substring(0, 2), StringComparison.InvariantCultureIgnoreCase) || wordMatch) && !userLocationObtained)
                    {
                        similar_Loc.Add(((string)json["name"]) + ": " + ((string)json["street"]) + " " + ((string)json["city"]) + " " + ((string)json["state"]));
                    }
                    else if ((tempinput.StartsWith(temp.Substring(0, 2), StringComparison.InvariantCultureIgnoreCase) || wordMatch) && userLocationObtained)
                    {
                        Geocoder        coder   = new Geocoder(act);
                        IList <Address> address = new List <Address>();


                        address = coder.GetFromLocationName(((string)json["street"]) + " " + ((string)json["city"]) + " " + ((string)json["state"]), 5);

                        float lon = (float)address.ElementAt(0).Longitude;
                        float lat = (float)address.ElementAt(0).Latitude;

                        tempAddress = new AddressLocator((string)json["name"], ((string)json["street"]) + " " + ((string)json["city"]) + " " + ((string)json["state"]), lon, lat);
                        mAddresses.Add(tempAddress);
                    }
                }
                if (userLocationObtained)
                {
                    //calculate distances
                    CalculateAddressDistance(mAddresses);
                    //sort distances
                    mAddresses.Sort();

                    for (int x = 0; x < mAddresses.Count; x++)
                    {
                        similar_Loc.Add(mAddresses.ElementAt(x).Name + ": " + mAddresses.ElementAt(x).Address + " (" + mAddresses.ElementAt(x).Distance.ToString("n2") + " miles)");
                    }
                }
            }

            mTv = act.FindViewById <ListView>(Resource.Id.searchResults);
            ArrayAdapter <string> arrayAdapter;

            if (searched_Loc.Count == 0 && similar_Loc.Count == 0)
            {
                Toast.MakeText(MainActivity.activity, "There were no results for that Location.", ToastLength.Long).Show();
                arrayAdapter = new ArrayAdapter <string>(act, Android.Resource.Layout.SimpleListItem1, similar_Loc);
            }
            else if (searched_Loc.Count == 0)
            {
                arrayAdapter = new ArrayAdapter <string>(act, Android.Resource.Layout.SimpleListItem1, similar_Loc);
            }
            else
            {
                arrayAdapter = new ArrayAdapter <string>(act, Android.Resource.Layout.SimpleListItem1, searched_Loc);
            }

            mTv.Adapter = arrayAdapter;
            mTv.SetFooterDividersEnabled(true);
            mTv.SetHeaderDividersEnabled(true);
        }
Example #25
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            //OnCreate takes a Bundle parameter, which is a dictionary for storing and passing state information
            //and objects between activities If the bundle is not null, this indicates the activity is restarting
            //and it should restore its state from the previous instance. "https:/docs.microsoft.com/en-us/xamarin/android/app-fundamentals/activity-lifecycle/"
            base.OnCreateView(inflater, container, savedInstanceState);
            //Once on create has finished, android will call OnStart which will start the activity

            //sets the layout of the main menu to the HomeCarePackagePage.axml file which is located in Resources/layout/
            View view = inflater.Inflate(Resource.Layout.HomeCarePackagePage, container, false);

            //setup lists for home care package data
            dataItems    = new List <HomeCarePackageData>();
            displayItems = new List <HomeCarePackageData>();
            searchItems  = new List <HomeCarePackageData>();

            //setup custom list adapter, more info found in HomeCarePackageViewAdapter.cs
            dataList = view.FindViewById <ListView>(Resource.Id.DataList);
            adapter  = new HomeCarePackageViewAdapter(this.Context, dataItems);

            //Display the number of items at the bottom of the page
            NumItems = view.FindViewById <TextView>(Resource.Id.txtNumData);

            //setup buttons at the top of the page which are used to sort the list based on the button pushed
            Button FName        = view.FindViewById <Button>(Resource.Id.FirstNameTextHomeCare);
            Button LName        = view.FindViewById <Button>(Resource.Id.LastNameTextHomeCare);
            Button PackageLevel = view.FindViewById <Button>(Resource.Id.PackageLevelText);
            Button IncomeList   = view.FindViewById <Button>(Resource.Id.PackageIncomeText);

            //setup Spinner to sort facilities
            Spinner spinner = view.FindViewById <Spinner>(Resource.Id.FacilitySpinner);

            spinner.Clickable     = false;
            spinner.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(Spinner_ItemSelected);
            var SpinnerAdapter = ArrayAdapter.CreateFromResource(view.Context, Resource.Array.FacilityArray, Android.Resource.Layout.SimpleSpinnerItem);//array found in Resources/values/

            SpinnerAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            spinner.Adapter = SpinnerAdapter;

            //create new WebClient class object which can provide methods to push and recieve data from an online resource via a url
            client = new WebClient();
            //set the url to push and pull data from, via the a Uri class object
            //the online resource is a php file hosted on heroku, these php files read write and pull database tables
            url = new Uri("https://capstonephpcode198.herokuapp.com/PullData.php");

            //setup toast message which is pop up message which informs the user that data is being pulled
            toastMessage = Toast.MakeText(this.Context, "Fetching data", ToastLength.Long);

            //setup graph button
            Button GraphButton = view.FindViewById <Button>(Resource.Id.GraphButton);

            GraphButton.Enabled = false;//disabled untill data is pulled
            GraphButton.Click  += delegate {
                var transaction            = ChildFragmentManager.BeginTransaction();
                HomeCarePackagesGraph info = new HomeCarePackagesGraph(displayItems);//displayItems to use all data
                info.Show(transaction, "dialog fragment");
            };

            //setup search bar
            SearchView SearchItems = view.FindViewById <SearchView>(Resource.Id.searchData);
            //an X apears next the search upon a submitted query, this X closes the current search, SearchCloseBtn button variable is associated with this
            //find the resource id's associated with the search and close buttons for the search bar widget
            int searchBtnID    = SearchItems.Context.Resources.GetIdentifier("android:id/search_button", null, null);
            int closeBtnID     = SearchItems.Context.Resources.GetIdentifier("android:id/search_close_btn", null, null);
            var SearchOpenBtn  = view.FindViewById <ImageView>(searchBtnID);
            var SearchCloseBtn = view.FindViewById <ImageView>(closeBtnID);

            SearchItems.SetIconifiedByDefault(false); //shows hint
            SearchItems.Enabled          = false;     //disable untill data is pulled
            SearchOpenBtn.Enabled        = false;
            SearchItems.QueryTextSubmit += delegate {
                //this search bar allows the user to search via first and/or last name
                string searchName = SearchItems.Query;
                //Get same string with first letter uppercase
                char firstUpper = searchName[0];
                firstUpper = Char.ToUpper(firstUpper);
                char[] searchNameLetters = searchName.ToCharArray();
                searchNameLetters[0] = firstUpper;
                string searchNameUpper = new string(searchNameLetters);

                foreach (HomeCarePackageData item in dataItems)
                {
                    //use searchItems list to hold all items while items get removed from the dataItems list if they don't match the search credentials
                    if (!searchItems.Contains(item))
                    {
                        searchItems.Add(item);
                    }
                }
                //if search credentials match or don't match, remove or add items from dataItems list
                foreach (HomeCarePackageData item in searchItems)
                {
                    bool foundFName      = String.Equals(searchName, item.GetResidentFirstName(), StringComparison.OrdinalIgnoreCase);//ignores upper or lower case
                    bool foundLName      = String.Equals(searchName, item.GetResidentLastName(), StringComparison.OrdinalIgnoreCase);
                    bool insideName      = item.GetResidentFirstName().Contains(searchName) || item.GetResidentLastName().Contains(searchName);
                    bool insideNameUpper = item.GetResidentFirstName().Contains(searchNameUpper) || item.GetResidentLastName().Contains(searchNameUpper);
                    if (dataItems.Contains(item) && !foundFName && !foundLName && !insideName && !insideNameUpper)
                    {
                        dataItems.Remove(item);
                    }
                    else if (!dataItems.Contains(item) && (foundFName || foundLName || insideName || insideNameUpper))
                    {
                        dataItems.Add(item);
                    }
                }
                SearchItems.ClearFocus();
                adapter.NotifyDataSetChanged();
            };
            //when the search bar close button is pressed, add all items from searchItems into dataItems
            SearchCloseBtn.Click += delegate {
                foreach (HomeCarePackageData item in searchItems)
                {
                    if (!dataItems.Contains(item))
                    {
                        dataItems.Add(item);
                    }
                }
                SearchItems.ClearFocus();
                SearchItems.SetQuery(String.Empty, false);
                adapter.NotifyDataSetChanged();
            };

            //setup progress bar
            ProgressBar ClientProgress = view.FindViewById <ProgressBar>(Resource.Id.ClientProgress);

            //show progress percentage on the bar
            client.UploadProgressChanged += delegate(object sender, UploadProgressChangedEventArgs e) {
                ClientProgress.Progress += e.ProgressPercentage;
            };
            //refresh button pulls data from database
            Button RefreshBtn = view.FindViewById <Button>(Resource.Id.RefreshButton);

            RefreshBtn.Click += delegate {
                RefreshBtn.SetBackgroundResource(Resource.Drawable.RefreshButtonIconClicked);//change refresh icon colour to lighter shade of green
                toastMessage.Show();
                spinner.SetSelection(0);
                //clear lists, to make way for updated data
                dataItems.Clear();
                displayItems.Clear();
                spinner.Clickable = false;

                NameValueCollection values = new NameValueCollection();
                values.Add("Type", "Home");
                //call php file and use UploadValuesAsync with the value of Type=Home so the php file knows to pull home care package data
                client.UploadValuesAsync(url, values);
            };

            client.UploadValuesCompleted += delegate(object sender, UploadValuesCompletedEventArgs e) {
                Activity.RunOnUiThread(() => {
                    string json = Encoding.UTF8.GetString(e.Result);
                    dataItems   = JsonConvert.DeserializeObject <List <HomeCarePackageData> >(json); //use json to create a list of data objects from the output of the php file
                    adapter     = new HomeCarePackageViewAdapter(this.Context, dataItems);           //setup adapter
                    foreach (HomeCarePackageData item in dataItems)
                    {
                        displayItems.Add(item);//display items holds all of the data objects for safe keeping, for when dataItems objects get removed
                    }
                    NumItems.Text    = dataItems.Count.ToString();
                    dataList.Adapter = adapter;
                    RefreshBtn.SetBackgroundResource(Resource.Drawable.RefreshButtonIcon);
                    spinner.Clickable     = true;
                    GraphButton.Enabled   = true;
                    SearchItems.Enabled   = true;
                    SearchOpenBtn.Enabled = true;
                    toastMessage.Cancel();
                    searchItems.Clear();
                    adapter.NotifyDataSetChanged();
                });
            };

            //setup button for sorting the list based on first names
            FName.Click += delegate {
                if (clickNumFName == 0)
                {
                    dataItems.Sort(delegate(HomeCarePackageData one, HomeCarePackageData two) {
                        return(string.Compare(one.GetResidentFirstName(), two.GetResidentFirstName()));
                    });
                    clickNumFName++;
                    clickNumLName  = 0;
                    clickNumIncome = 0;
                    clcikNumLevel  = 0;
                    //reverse list if clicked a second time in a row
                }
                else
                {
                    dataItems.Reverse();
                    clickNumFName = 0;
                }
                adapter.NotifyDataSetChanged();
            };

            //setup button for sorting the list based on last names
            LName.Click += delegate {
                if (clickNumLName == 0)
                {
                    dataItems.Sort(delegate(HomeCarePackageData one, HomeCarePackageData two) {
                        return(string.Compare(one.GetResidentLastName(), two.GetResidentLastName()));
                    });
                    clickNumLName++;
                    clickNumFName  = 0;
                    clickNumIncome = 0;
                    clcikNumLevel  = 0;
                    //reverse list if clicked a second time in a row
                }
                else
                {
                    dataItems.Reverse();
                    clickNumLName = 0;
                }
                adapter.NotifyDataSetChanged();
            };

            //setup button for sorting the list based on package levels
            PackageLevel.Click += delegate {
                if (clcikNumLevel == 0)
                {
                    dataItems.Sort(delegate(HomeCarePackageData one, HomeCarePackageData two) {
                        return(one.GetPackageLevel().CompareTo(two.GetPackageLevel()));
                    });
                    clcikNumLevel++;
                    clickNumLName  = 0;
                    clickNumFName  = 0;
                    clickNumIncome = 0;
                    //reverse list if clicked a second time in a row
                }
                else
                {
                    dataItems.Reverse();
                    clcikNumLevel = 0;
                }
                adapter.NotifyDataSetChanged();
            };

            //setup button for sorting the list based on incomes
            IncomeList.Click += delegate {
                if (clickNumIncome == 0)
                {
                    dataItems.Sort(delegate(HomeCarePackageData one, HomeCarePackageData two) {
                        return(one.GetPackageIncome().CompareTo(two.GetPackageIncome()));
                    });
                    clickNumIncome++;
                    clickNumLName = 0;
                    clickNumFName = 0;
                    clcikNumLevel = 0;
                    //reverse list if clicked a second time in a row
                }
                else
                {
                    dataItems.Reverse();
                    clickNumIncome = 0;
                }
                adapter.NotifyDataSetChanged();
            };

            return(view);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            Title = Resources.GetString(Resource.String.title_home);

            MyDrawerLayout    = FindViewById <DrawerLayout>(Resource.Id.drawer_layout);
            Search            = FindViewById <SearchView>(Resource.Id.search);
            SwipeRefresh      = FindViewById <SwipeRefreshLayout>(Resource.Id.refresh);
            SwipeRefreshEmpty = FindViewById <SwipeRefreshLayout>(Resource.Id.refreshEmpty);
            Fab = FindViewById <FloatingActionButton>(Resource.Id.fab);
            ListViewRepositories = FindViewById <MvxListView>(Resource.Id.listRep);

            MyToggle = new ActionBarDrawerToggle(this, MyDrawerLayout, Resource.String.open_drawer, Resource.String.close_drawer);
            MyDrawerLayout.AddDrawerListener(MyToggle);
            MyToggle.SyncState();



            ListViewRepositories.ViewTreeObserver.ScrollChanged += (sender, e) =>
            {
                if (ViewModel.Repositories != null && ViewModel.Repositories.Count > 0 && ListViewRepositories.LastVisiblePosition >= ViewModel.Repositories.Count() - 10)
                {
                    ViewModel.LoadMore(null);
                }
            };

            SwipeRefresh.Refresh      += Refresh;
            SwipeRefreshEmpty.Refresh += Refresh;

            Fab.Click += (sender, e) =>
            {
                if (ViewModel.SearchVisible)
                {
                    DoSearch();
                }
                else
                {
                    ViewModel.SearchVisible = true;
                    ShowKeyboard(Search);
                }
            };

            ListViewRepositories.ScrollStateChanged += (sender, e) =>
            {
                if (e.ScrollState == Android.Widget.ScrollState.Idle)
                {
                    Fab.Show();
                }
                else
                {
                    Fab.Hide();
                    ViewModel.SearchVisible = false;
                }
            };



            Search.SetIconifiedByDefault(false);

            Search.QueryTextChange += (object sender, SearchView.QueryTextChangeEventArgs e) =>
            {
                if (string.IsNullOrEmpty(Search.Query))
                {
                    DoSearch(false);
                }
            };
            Search.QueryTextSubmit += (object sender, SearchView.QueryTextSubmitEventArgs e) =>
            {
                DoSearch();
            };
        }
Example #27
0
        protected override void OnElementChanged(ElementChangedEventArgs <SearchBar> e)
        {
            base.OnElementChanged(e);

            searchView = Control;
            //linearLayout = Control;

            if (Control != null)
            {
                searchView.Iconified = false;
                searchView.SetIconifiedByDefault(false);
                searchView.BaselineAligned           = false;
                searchView.BaselineAlignedChildIndex = 0;

                /*
                 * linearLayout.RemoveAllViews();
                 * TextView label = new TextView(context);
                 * label.Text = "hola";
                 * linearLayout.AddView(label);
                 * Toolbar toolbar = new Toolbar(context);
                 * toolbar.AddView(new RadioButton(context));
                 * linearLayout.AddView(toolbar);
                 *
                 */

                //searchView.RemoveAllViews();
                //FormsTextView label = new FormsTextView(context);
                //label.Text = "holaaa";
                //searchView.AddView(label);

                // (Resource.Id.search_mag_icon); is wrong / Xammie bug

                //(icon as ImageView).SetImageResource(Resource.Drawable.search);

                //int cancelIconId = Context.Resources.GetIdentifier("android:id/search_close_btn", null, null);
                //var eicon = searchView.FindViewById(cancelIconId);
                //(eicon as ImageView).SetImageResource(Resource.Drawable.search);


                LinearLayout linearLayout = this.Control.GetChildAt(0) as LinearLayout;
                linearLayout = linearLayout.GetChildAt(2) as LinearLayout;
                linearLayout = linearLayout.GetChildAt(1) as LinearLayout;

                linearLayout.Background = null;                                                     //removes underline

                AutoCompleteTextView textView = linearLayout.GetChildAt(0) as AutoCompleteTextView; //modify for text appearance customization

                int searchIconId = Context.Resources.GetIdentifier("android:id/search_mag_icon", null, null);
                icon            = searchView.FindViewById(searchIconId);
                icon.Visibility = ViewStates.Invisible;
                icon.RemoveFromParent();

                var textView2Id = searchView.Context.Resources.GetIdentifier("android:id/search_src_text", null, null);
                var textView2   = (searchView.FindViewById(textView2Id) as EditText);
                if (textView == null)
                {
                    return;
                }
                textView.SetTextColor(global::Android.Graphics.Color.Black);

                IntPtr IntPtrtextViewClass        = JNIEnv.FindClass(typeof(TextView));
                IntPtr mCursorDrawableResProperty = JNIEnv.GetFieldID(IntPtrtextViewClass, "mCursorDrawableRes", "I");
                JNIEnv.SetField(Control.Handle, mCursorDrawableResProperty, Resource.Layout.design_layout_tab_text);                 // replace 0 with a Resource.Drawable.my_cursor

                Android.Widget.Button buttonFilter = new Android.Widget.Button(context);
                //buttonFilter.SetBackgroundResource(Resource.Drawable.ic_filter_list_black_24dp);
                //buttonFilter.SetBackgroundColor(Android.Graphics.Color.Transparent);
                //Toolbar toolbar = new Toolbar(context); toolbar = (toolbar.FindViewById(Resource.Layout.Toolbar) as Toolbar);

                //linearLayout.AddView(buttonFilter); <! IMPORTANTE !>

                //var editViewId = searchView.Context.Resources.GetIdentifier("android:id/search_plate", null, null);
                //var editView = (searchView.FindViewById(editViewId) as )

                //LinearLayout linearLayout = this.Control.GetChildAt(0) as LinearLayout;
                //linearLayout = linearLayout.GetChildAt(2) as LinearLayout;
                //linearLayout = linearLayout.GetChildAt(1) as LinearLayout;

                //AutoCompleteTextView textView = linearLayout.GetChildAt(0) as AutoCompleteTextView;
                //textView.SetTextColor(Android.Graphics.Color.Blue);
            }
            if (e.OldElement != null)
            {
            }
            if (e.NewElement != null)
            {
            }

            /*
             * if (e.NewElement == null)
             * {
             *
             *      GradientDrawable gd = new GradientDrawable();
             *      gd.SetStroke(0, Android.Graphics.Color.Transparent);
             *
             *      linearLayout.Background = gd;
             *
             *
             *      textView.SetBackgroundColor(Android.Graphics.Color.Red);
             *
             *      //ImageView icon = linearLayout.GetChildAt(1) as ImageView;
             *      //icon.Visibility = ViewStates.Invisible;
             *
             * }
             */
        }