Exemple #1
0
        private void SearchDictionary(string term)
        {
            if (term != SearchTerm)
            {
                SearchTerm = term;
            }

            TermTF.StringValue = SearchTerm;

            PreButton.Enabled  = NavigatorManager.IsCanBackWard;
            NextButton.Enabled = NavigatorManager.IsCanForWard;

            LegalDefinitionItem legalDefineItem = DictionaryUtil.SearchDictionary(term, TitleCountryCode);
            string htmlString = null;

            if (legalDefineItem == null ||
                legalDefineItem.ContextualDefinitions == null ||
                legalDefineItem.ContextualDefinitions.Count == 0)
            {
                htmlString = "<div id='content' style='width:140;height:20;margin-left:auto;margin-right:auto;margin-top:100px;margin-bottom:auto;'>No legal definition found.</div>";
            }
            else
            {
                htmlString = DictionaryHtmlStringFromLDItem(legalDefineItem, term);
                //Console.WriteLine ("{0}", htmlString);
            }

            DictionaryWebView.MainFrame.LoadHtmlString(htmlString, NSBundle.MainBundle.ResourceUrl);
        }
Exemple #2
0
        public String BuildHtml(LegalDefinitionItem definitions, string term, string version)
        {
            String contextualDefinitions = String.Empty;

            foreach (LegalContextualDefinitionItem definition in definitions.ContextualDefinitions)
            {
                contextualDefinitions += definitions.ContextualDefinitions.Count > 1 && definition.Context.Length > 0 ? "<span class='context'>" + definition.Context + "</span> " : String.Empty;
                contextualDefinitions += definition.DefinitionHtml;

                String relatedKeywords       = string.Join("; ", definition.AllRelatedKeywords.Select(k => k.HyperlinkTermKeyword));
                String relatedKeywordsLabel  = relatedKeywords.Length > 0 ? (contextualDefinitions.Length > 0 ? "See also: " : "See: ") : String.Empty;
                String relatedKeywordClosing = relatedKeywords.Length > 0 ? "." : "";

                contextualDefinitions += "<br/><br/>" + relatedKeywordsLabel + relatedKeywords + relatedKeywordClosing;
                contextualDefinitions += "<br/><br/>";
            }
            //#ed1c24
            const String cssBody =
                @"  <style type='text/css'>
                        body {color: Black; font-size:18px;font-family:'Segoe UI';}
                        h3 {color: Black; font-size:28px;font-weight:bold;font-family:'Segoe UI';}
                        .version { color: Black; font-size:11px; font-family:'Segoe UI'; text-align:right; font-style:italic; }
                        .Content { margin-right:12px;}
                        a, a:link, a:visited {color:#0D94FC;font-size:16px;font-weight:bold; text-decoration:none;}
                        a:hover {color:#1680FC; text-decoration:underline;}</style>";

            const String js =            //device-width
                              @"   <meta name='viewport' content='width=320, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no'/>
                     <meta http-equiv='Pragma' content='no-cache' />
                     <meta http-equiv='Expires' content='-1' />
                     <script src='ms-appx-web:///Html/Js/jquery.min.js'></script>
                     <script language='javascript' type='text/javascript'>
                     function ListenHref() {
                     $('a').click(function (e) {
                     if (this.href == null || this.href == '')
                     return false;  
                    var jsonObj = '{ type:\'href\',  value1:\'' + this.href + '\'}';
                    window.external.notify(jsonObj);
                    return false;
                    });};
                     </script>";

            string h = "<h3>" + term + "</h3>";
            string v = "<div class='version'>" + version + "</div>";

            String html =
                @"<html>
                    <head>" + js + cssBody + @"</head>
                    <body oncontextmenu='return false;'  onload='ListenHref();'>
                        <div id='content' class='Content' style='overflow-x:hidden;'>"
                + h + contextualDefinitions + v +
                "</div></body></html>";

            return(html);
        }
Exemple #3
0
        public LegalDefinitionItem SearchDictionary(string term, string countryCode)
        {
            LegalDefinitionItem result = new LegalDefinitionItem();
            List <LegalContextualDefinitionItem> contextualItemList = new List <LegalContextualDefinitionItem>();

            contextualItemList = base.GetEntityList <LegalContextualDefinitionItem>(Path.Combine(GlobalAccess.DirectoryService.GetAppExternalRootPath(),
                                                                                                 Constants.DICITIONARY_DB_NAME + countryCode + Constants.DICITIONARY_EXTENSION_NAME), queryString, term);

            if (GlobalAccess.Instance.CurrentUserInfo.Country.CountryCode.Equals(CountryEnum.AU.ToString()))
            {
                result.DictionaryVersionText = Constants.AU_DICTIONARY_VERSION_TEXT;
            }
            else
            {
                result.DictionaryVersionText = Constants.NZ_DICTIONARY_VERSION_TEXT;
            }

            foreach (LegalContextualDefinitionItem item in contextualItemList)
            {
                if (!String.IsNullOrEmpty(item.See))
                {
                    List <string> itemStringList = item.See.Split('|').ToList();
                    List <LegalRelatedKeywordItem> itemKeywordList = new List <LegalRelatedKeywordItem>();
                    foreach (string stringItem in itemStringList)
                    {
                        LegalRelatedKeywordItem kItem = new LegalRelatedKeywordItem(stringItem.Trim());
                        itemKeywordList.Add(kItem);
                    }
                    item.SeeKeywords = itemKeywordList;
                }

                if (!String.IsNullOrEmpty(item.SeeMore))
                {
                    List <string> itemStringList = item.SeeMore.Split('|').ToList();
                    List <LegalRelatedKeywordItem> itemKeywordList = new List <LegalRelatedKeywordItem>();
                    foreach (string stringItem in itemStringList)
                    {
                        LegalRelatedKeywordItem kItem = new LegalRelatedKeywordItem(stringItem.Trim());
                        itemKeywordList.Add(kItem);
                    }
                    item.SeeMoreKeywords = itemKeywordList;
                }
            }
            result.ContextualDefinitions = contextualItemList;
            return(result);
        }
Exemple #4
0
        public void SearchDictionary(string words, int bookId)
        {
            LegalDefinitionItem legalDefine = DictionaryUtil.SearchDictionary(words, AppDataUtil.Instance.GetCurrentPublication().BookId);

            if (legalDefine == null || legalDefine.ContextualDefinitions == null || legalDefine.ContextualDefinitions.Count == 0)
            {
                string htmlString = "<div id='content' style='width:240;height:40;margin-left:auto;margin-right:auto;font-size:22px;margin-top:150px;margin-bottom:auto;'>No legal definition found.</div>";                 //color:#A0A0A4; TextColor
                webView.LoadHtmlString(htmlString, NSUrl.FromString(""));
            }
            else
            {
                if (legalDefine.ContextualDefinitions.Count != 0)
                {
                    string html = BuildHtml(legalDefine, legalDefine.ContextualDefinitions[0].Term, legalDefine.DictionaryVersionText);
                    webView.LoadHtmlString(html, NSUrl.FromString(""));
                }
            }
        }
Exemple #5
0
        private String DictionaryHtmlStringFromLDItem(LegalDefinitionItem definitions, string term)
        {
            var version  = definitions.DictionaryVersionText;
            var count    = definitions.RelatedKeywordsCount;
            var itemList = definitions.ContextualDefinitions;

            String contextualDefinitions = String.Empty;
            string header = "<h3>" + term + "</h3>";

            contextualDefinitions += header;

            foreach (LegalContextualDefinitionItem definition in definitions.ContextualDefinitions)
            {
                contextualDefinitions += definitions.ContextualDefinitions.Count > 1 && definition.Context.Length > 0 ?
                                         "<span class='Item'>" + definition.Context + "</span>" : String.Empty;
                contextualDefinitions += definition.DefinitionHtml;

                String relatedKeywords      = string.Join("; ", definition.AllRelatedKeywords.Select(k => k.HyperlinkTermKeyword));
                String relatedKeywordsLabel = relatedKeywords.Length > 0 ? (contextualDefinitions.Length > 0 ?
                                                                            "See also: " : "See: ") : String.Empty;
                String relatedKeywordClosing = relatedKeywords.Length > 0 ? "." : "";

                contextualDefinitions += "<br><br>" + relatedKeywordsLabel + relatedKeywords + relatedKeywordClosing;
                contextualDefinitions += "<br><br>";
            }

            string dicVersion = "<div class='version'>" + version + "</div>";

            contextualDefinitions += dicVersion;

            if (File.Exists("Dictionary/Dictionary.html"))
            {
                var contentString = File.ReadAllText("Dictionary/Dictionary.html");

                contentString = contentString.Replace("#CONTENT#", contextualDefinitions);

                return(contentString);
            }
            else
            {
                return("");
                //return BuildHtml (definitions, term, version);
            }
        }
Exemple #6
0
        private async void SearchDictionary(string words)
        {
            BackBtn.IsEnabled = NavigatorManager.BackWard;
            NextBtn.IsEnabled = NavigatorManager.ForWard;
            Title.Text        = words;
            LegalDefinitionItem legalDefine = DictionaryUtil.SearchDictionary(Title.Text, CountryCode);

            if (legalDefine == null || legalDefine.ContextualDefinitions == null || legalDefine.ContextualDefinitions.Count == 0)
            {
                NoResultTitle.Visibility = Visibility.Visible;
            }
            else
            {
                NoResultTitle.Visibility = Visibility.Collapsed;
                string html = await BuildHtml(legalDefine, legalDefine.ContextualDefinitions[0].Term, legalDefine.DictionaryVersionText);

                LegalDefineDialog.NavigateToString(html);
            }
        }
Exemple #7
0
        /// <summary>
        /// SearchDictionary
        /// </summary>
        /// <param name="term"></param>
        /// <returns></returns>
        public static LegalDefinitionItem SearchDictionary(string term, int bookID)
        {
            LegalDefinitionItem result = new LegalDefinitionItem();
            string countryCode         = publicationAccess.GetDlBookByBookId(bookID, GlobalAccess.Instance.UserCredential).CountryCode.ToUpper();
            string dictionaryPath      = Path.Combine(GlobalAccess.DirectoryService.GetAppExternalRootPath(), Constants.DICITIONARY_DB_NAME + countryCode + Constants.DICITIONARY_EXTENSION_NAME);

            try
            {
                //bool pingResult = await connectionMonitor.PingService(GlobalAccess.Instance.CountryCode);

                //if (pingResult && DictionaryUtil.IsDictionaryDownloaded())
                //{
                //    DictionaryUtil.UpdateDictionary().Wait();
                //}

                if (!String.IsNullOrEmpty(term.Trim()))
                {
                    string keyword = term.Trim();
                    result = dictionaryAccess.SearchDictionary(keyword, countryCode);
                    if (result.ContextualDefinitions.Count == 0)
                    {
                        Regex replaceSpace = new Regex(@"\s{2,}", RegexOptions.IgnoreCase);
                        foreach (string punctuation in PUNCTUATION_LIST)
                        {
                            term = term.Replace(punctuation, Constants.SPACE);
                        }
                        keyword = replaceSpace.Replace(StringUtil.ToSingular(term.ToLower().Trim()), Constants.SPACE);
                        result  = dictionaryAccess.SearchDictionary(keyword, countryCode);
                    }
                    if (result.ContextualDefinitions.Count == 0)
                    {
                        result = dictionaryAccess.SearchDictionary(StringUtil.ToSingular(StringUtil.RemoveApostrophes(keyword)), countryCode);
                    }
                }
                return(result);
            }
            catch (Exception ex)
            {
                Logger.Log("Search Dictionary Failed : " + ex.Message);
                return(result);
            }
        }
Exemple #8
0
        private async Task <String> BuildHtml(LegalDefinitionItem definitions, string term, string version)
        {
            String contextualDefinitions = String.Empty;

            foreach (LegalContextualDefinitionItem definition in definitions.ContextualDefinitions)
            {
                contextualDefinitions += definitions.ContextualDefinitions.Count > 1 && definition.Context.Length > 0 ? "<span class='context'>" + definition.Context + "</span> " : String.Empty;
                contextualDefinitions += definition.DefinitionHtml;

                String relatedKeywords       = string.Join("; ", definition.AllRelatedKeywords.Select(k => k.HyperlinkTermKeyword));
                String relatedKeywordsLabel  = relatedKeywords.Length > 0 ? (contextualDefinitions.Length > 0 ? "See also: " : "See: ") : String.Empty;
                String relatedKeywordClosing = relatedKeywords.Length > 0 ? "." : "";
                contextualDefinitions += "<br/><br/>" + relatedKeywordsLabel + relatedKeywords + relatedKeywordClosing + "<br/><br/>";
            }
            string h    = "<h3>" + term + "</h3>";
            string v    = "<div class='version'>" + version + "</div>";
            string html = await HtmlHelper.DictionaryTemplateToString();

            html = html.Replace("#BODY#", h + contextualDefinitions + v);
            return(html);
        }
Exemple #9
0
        public void ShowAtLocation(View parent, Rect searchWordPos, string searchWord)
        {
            if (nav == null || nav.First.ToLower() != searchWord.ToLower())
            {
                nav = new Navigation(searchWord);
            }

            if (legalDefineResult == null ||
                string.IsNullOrEmpty(legalDefineResult.SearchTerm) ||
                legalDefineResult.SearchTerm.ToLower() != nav.Current.ToLower())
            {
                legalDefineResult            = DictionaryUtil.SearchDictionary(nav.Current, 1);
                legalDefineResult.SearchTerm = nav.Current;
            }

            this.searchWordPos = searchWordPos;
            var pos = GetPos();

            currentX = pos.Item1;
            currentY = pos.Item2;

            if (popup == null)
            {
                var view = host.LayoutInflater.Inflate(Resource.Layout.contentpage_legaldefine_popup, null);

                llContainer = view.FindViewById <LinearLayout>(Resource.Id.llContainer);

                tvSearchWord   = view.FindViewById <TextView>(Resource.Id.tvSearchWord);
                ivPreviousPage = view.FindViewById <ImageView>(Resource.Id.ivPreviousPage);
                ivNextPage     = view.FindViewById <ImageView>(Resource.Id.ivNextPage);
                tvDictWord     = view.FindViewById <TextView>(Resource.Id.tvDictWord);
                svContent      = view.FindViewById <ScrollView>(Resource.Id.svContent);
                tvContent      = view.FindViewById <TextView>(Resource.Id.tvContent);
                tvDicInfo      = view.FindViewById <TextView>(Resource.Id.tvDicInfo);
                tvSearchWeb    = view.FindViewById <TextView>(Resource.Id.tvSearchWeb);

                ivPreviousPage.Click += delegate
                {
                    if (nav.HasPrevious())
                    {
                        nav.Previous();
                        SearchDictionary();
                    }
                };

                ivNextPage.Click += delegate
                {
                    if (nav.HasNext())
                    {
                        nav.Next();
                        SearchDictionary();
                    }
                };

                tvSearchWeb.Click += delegate
                {
                    Uri uri    = Uri.Parse("https://www.google.com/search?q=" + URLEncoder.Encode(nav.First, "utf-8"));
                    var intent = new Intent(Intent.ActionView, uri);
                    intent.PutExtra(Browser.ExtraApplicationId, host.PackageName);
                    host.StartActivity(intent);
                };

                tvContent.MovementMethod = LinkMovementMethod.Instance;

                popup = new PopupWindow(
                    view,
                    ViewGroup.LayoutParams.WrapContent,
                    ViewGroup.LayoutParams.WrapContent,
                    true);
                popup.SetBackgroundDrawable(new ColorDrawable(Color.Rgb(255, 255, 255)));
                popup.OutsideTouchable = true;

                popup.SetOnDismissListener(new PopupDismissListener(this));

                //llContainer.SetOnTouchListener(new PopupOnTouchListener(this));
            }

            SetSearchWord();

            if (popup.IsShowing)
            {
                return;
            }

            //llContainer.ViewTreeObserver.AddOnGlobalLayoutListener(new PopupOnGlobalLayoutListener(this));
            popup.ShowAtLocation(parent, GravityFlags.NoGravity, pos.Item1, pos.Item2);
        }
Exemple #10
0
 private void SearchDictionary()
 {
     legalDefineResult            = DictionaryUtil.SearchDictionary(nav.Current, 1);
     legalDefineResult.SearchTerm = nav.Current;
     SetSearchWord();
 }