Beispiel #1
0
        //this method is called async (not from UI thread!) so making network request is possible here
        protected override FilterResults PerformFiltering(Java.Lang.ICharSequence constraint)
        {
            FilterResults filterResults = new FilterResults();
            if (constraint != null) {
                nn_adapter.resultlist=AutoFillManager.RetrieveInfo (constraint.ToString ());

                var tempcountry=(nn_adapter.nn_context!=null)? nn_adapter.nn_context.listcountry: nn_adapter.nn_context1.listcountry;
                var tempprovince=(nn_adapter.nn_context!=null)? nn_adapter.nn_context.liststateandprovince: nn_adapter.nn_context1.liststateandprovince;
                RetrievedInfo[] flag = new RetrievedInfo[nn_adapter.resultlist.Count];

                for(int i=0;i<nn_adapter.resultlist.Count;i++){
                    var tempobj = nn_adapter.resultlist [i];
                    bool countryflag=false;
                    bool provinceflag=false;
                    foreach(var country in tempcountry){
                        if(country.country_name.Equals(tempobj.country)){
                            countryflag = true;
                        }
                    }
                    foreach(var province in tempprovince){
                        if(province.state_province_name.Equals(tempobj.state)){
                            provinceflag = true;
                        }
                    }
                    if(!(countryflag&&provinceflag)){
                        flag [i] = tempobj;
                    }
                }
                for (int i = 0; i < flag.Length; i++) {
                    if (flag [i]!=null) {
                        nn_adapter.resultlist.Remove(flag[i]);
                    }
                }

                nn_adapter.resultarraylist=new ArrayList(nn_adapter.resultlist);
                filterResults.Values = nn_adapter.resultarraylist;
                filterResults.Count = nn_adapter.resultarraylist.Size();
            }
            return filterResults;
        }
Beispiel #2
0
 public static void AddInfoObject(RetrievedInfo retrieveinfo)
 {
     lock (infolistlocker) {
         list.Add (retrieveinfo);
     }
 }
Beispiel #3
0
        public void Run(object obj)
        {
            try{
                string jsonstr = "";
                string url =String.Format("https://maps.googleapis.com/maps/api/place/details/json?placeid={0}&key={1}",nn_placeid,AutoFillManager.Key);

                RetrievedInfo temp=new RetrievedInfo();
                HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
                webRequest.ProtocolVersion = HttpVersion.Version10;
                webRequest.Method = "GET";
                webRequest.ContentType = "application/x-www-form-urlencoded";
                webRequest.Timeout = 15000;//15 sec
                using (WebResponse response = webRequest.GetResponse())
                {
                    StringBuilder stringbuilder = new StringBuilder();
                    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                    {
                        string line;
                        while ((line = reader.ReadLine()) != null)
                        {
                            stringbuilder.Append(line);
                        }
                    }
                    jsonstr=stringbuilder.ToString();
                }

                if(!string.IsNullOrEmpty(jsonstr)){
                    var jValue = JsonObject.Parse (jsonstr);
                    if (jValue["result"]["address_components"]!=null) {
                        var returnlist = jValue ["result"]["address_components"];

                        foreach (var item in returnlist) {
                            DetailObj detailobject = JsonConvert.DeserializeObject<DetailObj> (item.ToString ());
                            if(detailobject.types[0].Equals("street_number")){
                                temp.streetnumber=detailobject.long_name;
                            }
                            if(detailobject.types[0].Equals("route")){
                                temp.streetname=detailobject.long_name;
                            }
                            //city
                            if(detailobject.types[0].Equals("locality")){
                                temp.city=detailobject.long_name;
                            }
                            //state
                            if(detailobject.types[0].Equals("administrative_area_level_1")){
                                temp.state=detailobject.long_name;
                            }
                            if(detailobject.types[0].Equals("country")){
                                temp.country=detailobject.long_name;
                            }
                            if(detailobject.types[0].Equals("postal_code")){
                                temp.zipcode=detailobject.long_name;
                            }
                        }
                        AutoFillManager.AddInfoObject(temp);
                    }
                }

            }catch(Exception e){
                Console.WriteLine ("hahshas");
            }finally{
                nn_setevent.Set ();
            }
        }