Esempio n. 1
0
        //https://philio.me/styling-the-searchview-with-appcompat-v21/
        //https://code.google.com/p/android/issues/detail?id=70754
        public void Init(string searchIdName, string textFieldHint, bool topLine, bool serachLine, bool bottomline = false)
        {
            _stoppingPlaceViewModel = Stops.Setup.IoC.Container.Get <Core.ViewModels.SearchViewModel> ();


            /*
             * Load last selected on startup
             */
            _searchView           = _view.FindViewById <Android.Support.V7.Widget.SearchView> (Resource.Id.SearchFragmentSearch);
            _searchView.QueryHint = textFieldHint;
            _searchView.SetOnQueryTextListener(this);
            _searchView.SetOnSuggestionListener(this);

            ((EditText)_searchView.FindViewById(Resource.Id.search_src_text)).CustomSelectionActionModeCallback
                = this;

            if (mSuggestionsAdapter == null)
            {
                MatrixCursor cursor = new MatrixCursor(COLUMNS);
                mSuggestionsAdapter = new SuggestionsAdapter(Android.App.Application.Context, cursor);
            }

            _searchView.SuggestionsAdapter = mSuggestionsAdapter;


            if (!topLine)
            {
                var topLineView = _view.FindViewById <FrameLayout> (Resource.Id.SearchFragmentTopLine);
                topLineView.Visibility = topLine ? ViewStates.Visible : ViewStates.Gone;
            }

            if (!serachLine)
            {
                var view = _view.FindViewById <FrameLayout> (Resource.Id.SearchFragmentDragLine);
                view.Visibility = serachLine ? ViewStates.Visible : ViewStates.Gone;
            }
            if (!bottomline)
            {
                var view = _view.FindViewById <FrameLayout>(Resource.Id.SearchFragmentBottomLine);
                view.Visibility = serachLine ? ViewStates.Visible : ViewStates.Gone;
            }

            int searchEditTextId = Resource.Id.search_src_text;             // for AppCompat

            // get AutoCompleteTextView from SearchView
            AutoCompleteTextView searchEditText = (AutoCompleteTextView)_searchView.FindViewById(searchEditTextId);
            View dropDownAnchor = _searchView.FindViewById(searchEditText.DropDownAnchor);

            dropDownAnchor.AddOnLayoutChangeListener(this);

            searchEditText.LongClick += (object sender, View.LongClickEventArgs e) => {
                SetChoicedStop(null);
            };

            /*
             * Init the view model and set the last chocied stop
             */
            _stoppingPlaceViewModel.Init(searchIdName);
            if (_stoppingPlaceViewModel.HasLatestCLickeStop())
            {
                _choicedStop = _stoppingPlaceViewModel.GetLatestCLickeStop();
                _ignoreAutoCompleteTextChange = true;

                _searchView.SetQuery(_choicedStop.Name, true);
                Events.Trigger("initWithStop", _choicedStop, 100);
            }

            var btnPos = _view.FindViewById <ImageButton> (Resource.Id.btnPos);

            btnPos.Click += (object sender, EventArgs e) => {
                Events.Trigger("locationClick", null);
                return;
            };
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            try
            {
                this.Window.SetSoftInputMode(SoftInput.AdjustNothing);

                base.OnCreate(savedInstanceState);

                IMethods.IApp.FullScreenApp(this);

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

                var ToolBar = FindViewById <Toolbar>(Resource.Id.mainSearchtoolbar);
                SetSupportActionBar(ToolBar);
                SupportActionBar.SetDisplayShowCustomEnabled(true);
                SupportActionBar.SetDisplayShowTitleEnabled(false);
                SupportActionBar.SetDisplayHomeAsUpEnabled(true);
                SupportActionBar.SetHomeButtonEnabled(true);
                SupportActionBar.SetDisplayShowHomeEnabled(true);

                //Get values
                SearchRecyler      = FindViewById <RecyclerView>(Resource.Id.searchRecylerview);
                Btn_SearchRandom   = FindViewById <Button>(Resource.Id.SearchRandom_Button);
                OnlineSearch_Empty = FindViewById <LinearLayout>(Resource.Id.OnlineSearch_LinerEmpty);


                swipeRefreshLayout = FindViewById <SwipeRefreshLayout>(Resource.Id.swipeRefreshLayout);
                swipeRefreshLayout.SetColorSchemeResources(Android.Resource.Color.HoloBlueLight,
                                                           Android.Resource.Color.HoloGreenLight, Android.Resource.Color.HoloOrangeLight,
                                                           Android.Resource.Color.HoloRedLight);
                swipeRefreshLayout.Enabled = false;

                FloatingActionButtonView = FindViewById <FloatingActionButton>(Resource.Id.floatingActionButtonView);

                //Set Adapter
                mLayoutManager = new LinearLayoutManager(this);
                SearchRecyler.SetLayoutManager(mLayoutManager);
                mAdapter = new SearchUser_Adapter(this);
                mAdapter.mSearchUserList = new ObservableCollection <GetSearchObject.User>();
                SearchRecyler.SetAdapter(mAdapter);


                var data = Intent.GetStringExtra("Key") ?? "Data not available";
                if (data != "Data not available" && !String.IsNullOrEmpty(data))
                {
                    if (search_key == "Random")
                    {
                        search_key = "a";
                        GetSearch_Result("a");
                    }
                    else
                    {
                        search_key = data;
                        if (_SearchView != null)
                        {
                            _SearchView.SetQuery(search_key, false);
                            _SearchView.ClearFocus();
                            _SearchView.OnActionViewCollapsed();
                        }

                        GetSearch_Result(search_key);
                    }
                }

                //Close keybourd
                InputMethodManager inputManager = (InputMethodManager)this.GetSystemService(Activity.InputMethodService);
                if (inputManager.IsActive)
                {
                    if (ToolBar != null)
                    {
                        inputManager = (InputMethodManager)this.GetSystemService(Activity.InputMethodService);
                        inputManager.HideSoftInputFromWindow(ToolBar.WindowToken, 0);
                    }
                }

                _SearchView.ClearFocus();

                AdsGoogle.Ad_Interstitial(this);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }