コード例 #1
0
 public override void OnBackPressed() // BackPressed or Save button clicked
 {
     try
     {
         if (string.IsNullOrEmpty(workEditText.Text))
         {
             throw new ArgumentNullException();                                          // not saving if text is empty
         }
         if (work == null)
         {
             work = new Work();               // if not loaded creating new work
         }
         if (string.IsNullOrEmpty(titleEditText.Text))
         {
             titleEditText.Text = "Nowe dzieło (" + (SQLiteDb.GetWorks().Where(w => w.Title.Contains("Nowe dzieło")).Count() + 1) + ")"; // filling title if empty
         }
         if (work.Text != workEditText.Text || work.Title != titleEditText.Text)                                                         //saving work if changed or new
         {
             work.Text     = workEditText.Text;
             work.Title    = titleEditText.Text;
             work.Modified = DateTime.Now;
             SQLiteDb.SaveWork(work);
         }
         else
         {
             throw new ArgumentNullException();
         }
     }
     catch
     {
         Toast.MakeText(this, "Nie zapisano", ToastLength.Short).Show();
     }
     base.OnBackPressed();
 }
コード例 #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(toolbar);

            FloatingActionButton fab = FindViewById <FloatingActionButton>(Resource.Id.fab);

            fab.Click += FabOnClick;

            //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);

            worksList    = SQLiteDb.GetWorks();
            mainListView = FindViewById <ListView>(Resource.Id.mainListView);
            mainListView.SetSelection(0);

            mainListView.ItemClick     += MainListView_ItemClick;
            mainListView.ItemLongClick += MainListView_ItemLongClick;
            UpdateAdapter();
            SQLiteDb.StartApp(this); // starting load words to library
        }
コード例 #3
0
        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            int id = item.ItemId;

            if (id == Resource.Id.deleteItems)
            {
                toolbar.Menu.FindItem(Resource.Id.deleteItems).SetVisible(false);
                toolbar.Menu.FindItem(Resource.Id.cancelDeletingItems).SetVisible(false);
                deletingItems = false;
                SQLiteDb.DeleteWorks(worksToDelete);
                worksList = SQLiteDb.GetWorks();
                UpdateAdapter();
                return(true);
            }
            if (id == Resource.Id.cancelDeletingItems)
            {
                toolbar.Menu.FindItem(Resource.Id.deleteItems).SetVisible(false);
                toolbar.Menu.FindItem(Resource.Id.cancelDeletingItems).SetVisible(false);
                UpdateAdapter();
                deletingItems = false;
                return(true);
            }
            return(base.OnOptionsItemSelected(item));
        }
コード例 #4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.WorkLayout);

            // View elements
            var saveImageButton = FindViewById <ImageButton>(Resource.Id.SaveWorkImageButton);

            titleEditText     = FindViewById <EditText>(Resource.Id.TitleEditText);
            syllabelsTextView = FindViewById <TextView>(Resource.Id.SyllablesCountTextView);
            workEditText      = FindViewById <EditText>(Resource.Id.WorkEditText);

            findSynonymsButton = FindViewById <Button>(Resource.Id.FindSynonymsButton);
            findRhymesButton   = FindViewById <Button>(Resource.Id.FindRhymesButton);

            searchButton          = FindViewById <Button>(Resource.Id.SearchButton);
            searchEditText        = FindViewById <SearchView>(Resource.Id.SearchEditText);
            searchingLinearLayout = FindViewById <LinearLayout>(Resource.Id.SearchingLinearLayout);

            numberPickersLinearLayout = FindViewById <LinearLayout>(Resource.Id.NumberPickersLinearLayout);

            var matchingNumberTextView       = FindViewById <TextView>(Resource.Id.MatchingNumberTextView);
            var matchingNumberDecreaseButton = FindViewById <Button>(Resource.Id.MatchingNumberDecreaseButton);
            var matchingNumberIncreaseButton = FindViewById <Button>(Resource.Id.MatchingNumberIncreaseButton);

            var lengthNumberTextView       = FindViewById <TextView>(Resource.Id.LengthNumberTextView);
            var lengthNumberDecreaseButton = FindViewById <Button>(Resource.Id.LengthNumberDecreaseButton);
            var lengthNumberIncreaseButton = FindViewById <Button>(Resource.Id.LengthNumberIncreaseButton);

            var syllablesNumberTextView       = FindViewById <TextView>(Resource.Id.SyllablesNumberTextView);
            var syllablesNumberDecreaseButton = FindViewById <Button>(Resource.Id.SyllablesNumberDecreaseButton);
            var syllablesNumberIncreaseButton = FindViewById <Button>(Resource.Id.SyllablesNumberIncreaseButton);


            syllabelsTextView.Visibility = ViewStates.Gone;
            findSynonymsButton.Click    += FindSynonymsButton_Click;
            typeface = findSynonymsButton.Typeface;
            workEditText.TextChanged += WorkEditText_TextChanged;
            findRhymesButton.Click   += FindRhymesButton_Click;

            //matching number picker
            {
                matchingNumberDecreaseButton.Click += (o, e) => //decreasing number of matching letters
                {
                    if (matchingNumberTextView.Text != "1")
                    {
                        matchingNumberTextView.Text = (Convert.ToInt32(matchingNumberTextView.Text) - 1).ToString();
                    }
                };
                matchingNumberDecreaseButton.LongClick += (o, e) => // fast decreasing
                {
                    matchingNumberTextView.Text = "1";
                };
                matchingNumberIncreaseButton.Click += (o, e) => //increasing number of matching letters
                {
                    matchingNumberTextView.Text = (Convert.ToInt32(matchingNumberTextView.Text) + 1).ToString();
                };
            }

            //length number picker
            {
                lengthNumberDecreaseButton.Click += (o, e) => //decreasing number of words length
                {
                    if (lengthNumberTextView.Text != "1")
                    {
                        lengthNumberTextView.Text = (Convert.ToInt32(lengthNumberTextView.Text) - 1).ToString();
                    }
                };
                lengthNumberDecreaseButton.LongClick += (o, e) => // fast decreasing
                {
                    lengthNumberTextView.Text = "1";
                };
                lengthNumberIncreaseButton.Click += (o, e) => //increasing number of words length
                {
                    lengthNumberTextView.Text = (Convert.ToInt32(lengthNumberTextView.Text) + 1).ToString();
                };
            }

            //syllables number picker
            {
                syllablesNumberDecreaseButton.Click += (o, e) => //decreasing number of syllables
                {
                    if (syllablesNumberTextView.Text != "1")
                    {
                        syllablesNumberTextView.Text = (Convert.ToInt32(syllablesNumberTextView.Text) - 1).ToString();
                    }
                };
                syllablesNumberDecreaseButton.LongClick += (o, e) => // fast decreasing
                {
                    syllablesNumberTextView.Text = "1";
                };
                syllablesNumberIncreaseButton.Click += (o, e) => //increasing number of syllables
                {
                    syllablesNumberTextView.Text = (Convert.ToInt32(syllablesNumberTextView.Text) + 1).ToString();
                };
            }

            //search button clicked
            searchButton.Click += (o, e) =>
            {
                if (searchEditText.Query != "") // searching if not empty
                {
                    var progressBar = FindViewById <ProgressBar>(Resource.Id.SearchingContentLoadingProgressBar);
                    progressBar.Visibility = ViewStates.Visible;
                    var intent = new Intent(this, typeof(SearchActivity));
                    intent.PutExtra("KindOfSearching", toSearch);
                    intent.PutExtra("ToFind", searchEditText.Query);
                    if (toSearch == "Rhymes")
                    {
                        intent.PutExtra("MatchingNumber", Convert.ToInt32(matchingNumberTextView.Text));
                        intent.PutExtra("Length", Convert.ToInt32(lengthNumberTextView.Text));
                        intent.PutExtra("Syllables", Convert.ToInt32(syllablesNumberTextView.Text));
                        findRhymesButton.PerformClick();
                    }
                    else
                    {
                        findSynonymsButton.PerformClick();
                    }
                    StartActivityForResult(intent, 1);
                    progressBar = null;
                    intent      = null;
                }
            };

            //search button clicked on keayboard
            searchEditText.QueryTextSubmit += (o, e) =>
            {
                searchButton.PerformClick();
            };

            colors = findSynonymsButton.TextColors;                       //saving states of button text colors

            findSynonymsButton.SetTextColor(Android.Graphics.Color.Gray); //setting buttons text grey color
            findRhymesButton.SetTextColor(Android.Graphics.Color.Gray);

            // loading work if id was passed
            var choosenWorkId = Intent.GetIntExtra("choosenWork", 0);

            if (choosenWorkId != 0)
            {
                work = SQLiteDb.GetWorks().First(w => w.Id == choosenWorkId);
                workEditText.Text  = work.Text;
                titleEditText.Text = work.Title;
            }

            saveImageButton.Click += (o, e) => // saving work with save button
            {
                OnBackPressed();
            };
            CheckIfDataLoaded();
        }
コード例 #5
0
 protected override void OnRestart() // reload list when coming back from work
 {
     base.OnRestart();
     worksList = SQLiteDb.GetWorks();
     UpdateAdapter();
 }