public override void OnBackPressed()
        {
            Stack <Fragment> stack = stacks[(int)App.STATE.CurrentLibrary];

            if (stack.Count > 0)
            {
                if (stack.Count == 1)
                {
                    drawer.SetDrawerLockMode(DrawerLayout.LockModeLockedClosed, nav);
                }
                base.OnBackPressed();
            }
            else
            {
                MaterialDialog         dialog = null;
                MaterialDialog.Builder popup  = new MaterialDialog.Builder(this);
                popup.SetTitle("Exit Application?");
                popup.SetPositiveText("Yes", (o, e) =>
                {
                    base.OnBackPressed();
                });
                popup.SetNegativeText("No");

                dialog = popup.Show();
            }
        }
Esempio n. 2
0
        public void ShowFontSizeDialog()
        {
            SeekBar seek = new SeekBar(Activity);

            seek.Max              = 10;
            seek.Progress         = App.STATE.SeekBarTextSize;
            seek.ProgressChanged += (o, e) =>
            {
                int size = App.FUNCTIONS.GetWebViewTextSize(e.Progress);

                SetWebViewTextSize(size);

                // Set font size globally
                App.STATE.SeekBarTextSize = e.Progress;

                // Save font size to preferences
                var prefs = PreferenceManager.GetDefaultSharedPreferences(Activity);
                prefs.Edit().PutInt("WebViewBaseFontSize", e.Progress).Commit();
            };

            MaterialDialog dialog = null;

            MaterialDialog.Builder popup = new MaterialDialog.Builder(Activity);
            popup.SetCustomView(seek, false);
            popup.SetTitle("Text Size");
            popup.SetPositiveText("X");

            dialog = popup.Show();
        }
Esempio n. 3
0
        public void ShowCharacterLearningDialog(Context context, LearningCharacter character, WebView webview)
        {
            SQLiteConnection database = new SQLiteConnection(App.LearningCharactersPath);

            database.CreateTable <LearningCharacter>();

            var  table  = database.Table <LearningCharacter>();
            bool exists = table.Any(x => x.Chinese.Equals(character.Chinese) && x.Pinyin.Equals(character.Pinyin));

            string buttonTitle = (exists) ? "REMOVE" : "ADD";

            MaterialDialog.Builder popup = new MaterialDialog.Builder(context);
            popup.SetTitle(character.Chinese + " " + character.Pinyin);
            popup.SetContent(character.English);
            popup.SetPositiveText(buttonTitle, (o, e) =>
            {
                if (!exists)
                {
                    database.Insert(character);
                }
                if (exists)
                {
                    var query = (from c in table
                                 where (c.Chinese.ToLower().Equals(character.Chinese.ToLower()) && c.Pinyin.ToLower().Equals(character.Pinyin.ToLower()))
                                 select c).ToList().FirstOrDefault();

                    database.Delete(query);
                }
                string js = "javascript:ToggleEnglish();";
                webview.LoadUrl(js);
            });

            App.STATE.Activity.RunOnUiThread(() =>
            {
                popup.Show();
            });
        }
 public virtual Builder SetTitle(int titleId)
 {
     builder.SetTitle(titleId);
     return(this);
 }
        private void ShowChapterPrompt(string storehouse, WOLPublication pub, NavStruct article)
        {
            LayoutInflater       inflater = (LayoutInflater)Activity.GetSystemService(Context.LayoutInflaterService);
            View                 view     = inflater.Inflate(Resource.Layout.DialogChapterSelect, null);
            HeaderFooterGridView gridview = view.FindViewById <HeaderFooterGridView>(Resource.Id.chapterSelectGridView);

            gridview.SetSelector(Android.Resource.Color.Transparent);

            List <WOLArticle> articles;
            List <ISpanned>   titles;

            if (LibraryMode == Library.Bible)
            {
                gridview.NumColumns  = -1;
                gridview.StretchMode = StretchMode.NoStretch;

                string bookNumber = article.Book.ToString() + ".";

                articles = JwStore.QueryArticleChapterTitles(PublicationType.Bible, storehouse)
                           .Where(a => a.ArticleNumber.StartsWith(bookNumber)).ToList();

                titles = articles.Select(a => Html.FromHtml(a.ArticleTitle.ToString().Split(new[] { ' ' }).Last())).ToList();
                if (titles.Count == 1)
                {
                    LoadArticle(article);

                    return;
                }
            }
            else if (LibraryMode == Library.Insight)
            {
                gridview.NumColumns  = 2;
                gridview.StretchMode = StretchMode.StretchColumnWidth;

                articles = JwStore.QueryArticleChapterTitles(PublicationType.Insight, storehouse)
                           .Where(i => i.ArticleGroup.Equals(pub.Group))
                           .ToList();

                titles = articles.Select(a => Html.FromHtml(a.ArticleTitle.Replace("\n", "<br/>").Split('<')[0] + "<br/><i>" + a.ArticleLocation + "</i>")).ToList();
            }
            else
            {
                gridview.NumColumns  = 1;
                gridview.StretchMode = StretchMode.StretchColumnWidth;

                articles = JwStore.QueryArticleChapterTitles(pub.Code, storehouse)
                           .ToList();

                titles = articles.Select(a => Html.FromHtml(a.ArticleTitle.Replace("\n", "<br/>").Split('<')[0] + "<br/><i>" + a.ArticleLocation + "</i>")).ToList();
                if (titles.Count == 1)
                {
                    LoadArticle(article);

                    return;
                }
            }

            MaterialDialog dialog = null;

            gridview.Adapter    = new ArticleButtonAdapter(Activity, titles.ToArray());
            gridview.ItemClick += (s, args) =>
            {
                dialog.Dismiss();

                article = NavStruct.Parse(articles[args.Position].ArticleNumber);
                LoadArticle(article);
            };

            MaterialDialog.Builder popup = new MaterialDialog.Builder(Activity);
            popup.SetCustomView(view, false);
            popup.SetTitle(pub.Name.Replace("\n", "<br/>").Split('<')[0]);
            popup.SetNegativeText("X");

            dialog = popup.Show();
        }
Esempio n. 6
0
        public void ShowChapterPrompt()
        {
            string title = gridViewTitle.Text;

            LayoutInflater       inflater = (LayoutInflater)Activity.GetSystemService(Context.LayoutInflaterService);
            View                 view     = inflater.Inflate(Resource.Layout.DialogChapterSelect, null);
            HeaderFooterGridView grid     = view.FindViewById <HeaderFooterGridView>(Resource.Id.chapterSelectGridView);

            grid.SetSelector(Android.Resource.Color.Transparent);
            if (Build.VERSION.SdkInt >= BuildVersionCodes.Honeycomb)
            {
                grid.ChoiceMode = ChoiceMode.Single;
            }

            List <ISpanned> articles;

            if (library == Library.Bible)
            {
                // Chapter numbers only
                articles         = primaryChapters.Select(a => Html.FromHtml(a.ToString().Split(new[] { ' ' }).Last())).ToList();
                grid.StretchMode = StretchMode.NoStretch;
                grid.NumColumns  = -1;
            }
            else if (library == Library.Insight)
            {
                // Article titles
                articles         = primaryChapters;
                grid.StretchMode = StretchMode.StretchColumnWidth;
                grid.NumColumns  = 2;
            }
            else
            {
                // Article titles
                articles         = primaryChapters;
                grid.StretchMode = StretchMode.StretchColumnWidth;
                grid.NumColumns  = 1;
            }

            // If one article, do nothing
            if (articles.Count == 1)
            {
                return;
            }

            MaterialDialog dialog = null;

            grid.Adapter    = new ArticleButtonAdapter(Activity, articles.ToArray());
            grid.ItemClick += SelectChapter;
            grid.ItemClick += delegate
            {
                dialog.Dismiss();
            };

            int index = GetNavigationIndex();

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Honeycomb)
            {
                grid.SetItemChecked(index, true);
            }
            grid.SetSelection(index);

            MaterialDialog.Builder popup = new MaterialDialog.Builder(Activity);
            popup.SetCustomView(view, false);
            popup.SetTitle(title.Replace("\n", "<br/>").Split('<')[0]);
            popup.SetNegativeText("X");

            dialog = popup.Show();
        }
        public void BuildStorehouseWorker()
        {
            worker.WorkerSupportsCancellation = true;
            worker.DoWork += (object sender, DoWorkEventArgs e) =>
            {
                MaterialDialog.Builder progress = new MaterialDialog.Builder(this);
                progress.SetTitle("Finalizing Storehouse");
                progress.SetContent("Please be patient");
                progress.SetCancelable(false);
                progress.SetProgress(true, 3);

                MaterialDialog dialog = null;

                RunOnUiThread(() =>
                {
                    dialog = progress.Show();
                });

                RunOnUiThread(() =>
                {
                    dialog.SetContent("Building English library");
                });
                App.FUNCTIONS.ExtractDatabase("english.db", this, MAIN_EXPANSION_FILE_VERSION);
                RunOnUiThread(() =>
                {
                    dialog.SetContent("Building Chinese library");
                });
                App.FUNCTIONS.ExtractDatabase("chinese.db", this, MAIN_EXPANSION_FILE_VERSION);
                RunOnUiThread(() =>
                {
                    dialog.SetContent("Building Pinyin library");
                });
                App.FUNCTIONS.ExtractDatabase("pinyin.db", this, MAIN_EXPANSION_FILE_VERSION);

                List <Library> libraries = new List <Library>();
                libraries.Add(Library.Bible);
                libraries.Add(Library.Insight);
                libraries.Add(Library.DailyText);
                libraries.Add(Library.Publications);

                App.STATE.Libraries      = libraries;
                App.STATE.CurrentLibrary = libraries.First();

                App.STATE.SeekBarTextSize = Resources.GetInteger(Resource.Integer.webview_base_font_size);

                // English
                App.STATE.PrimaryLanguage = App.FUNCTIONS.GetAvailableLanguages(this)[0];
                // Chinese
                App.STATE.SecondaryLanguage = App.FUNCTIONS.GetAvailableLanguages(this)[1];
                // Pinyin
                App.STATE.PinyinLanguage = App.FUNCTIONS.GetAvailableLanguages(this)[2];
                // Set current language first to English
                App.STATE.Language = App.STATE.PrimaryLanguage.EnglishName;

                App.STATE.SaveUserPreferences();
                preferences.Edit().PutInt("MainExpansionFileVersion", MAIN_EXPANSION_FILE_VERSION).Commit();

                RunOnUiThread(() =>
                {
                    Toast.MakeText(this, "Set up complete. Have fun!", ToastLength.Long).Show();
                });

                dialog.Dismiss();

                StartApplication();
            };

            worker.RunWorkerCompleted += (object sender, RunWorkerCompletedEventArgs e) =>
            {
                Console.WriteLine("WORKER COMPLETE!");
            };
        }