Exemplo n.º 1
0
		protected override void OnCreate (Bundle savedInstanceState)
		{
			base.OnCreate (savedInstanceState);
		
			SetContentView (Resource.Layout.main);
			var textView = FindViewById<TextView> (Resource.Id.textView);

			// create an object
			var account = new Account ("Xamarin", "Corporate");

			// create the serializer
			var gson = new GsonBuilder ()
				.SetPrettyPrinting ()
				.Create ();

			// serialize the object into json
			var json = gson.ToJson (account);

			// deserialize the json into the object
			var clazz = Java.Lang.Class.FromType (typeof(Account));
			var newAccount = (Account)gson.FromJson (json, clazz);

			textView.Text = string.Join (System.Environment.NewLine, new [] { 
				json, 
				"Name == 'Xamarin': " + (newAccount.Name == "Xamarin"), 
				"Type == 'Corporate': " + (newAccount.Type == "Corporate") 
			});
		}
Exemplo n.º 2
0
        public void SetRequest(string nodeKey, object obj, Action onSuccess = null, Action <string> onError = null)
        {
            DatabaseReference dr = FirebaseDatabase.Instance.GetReference("requests");
            var req = dr.Child(nodeKey);

            if (dr != null)
            {
                if (obj != null)
                {
                    string objJsonString = JsonConvert.SerializeObject(obj);

                    Gson gson = new GsonBuilder().SetPrettyPrinting().Create();

                    HashMap dataHashMap = new HashMap();

                    Java.Lang.Object jsonObj = gson.FromJson(objJsonString, dataHashMap.Class);

                    dataHashMap = jsonObj.JavaCast <HashMap>();


                    req.SetValue(dataHashMap);
                }
                else
                {
                    req.Child("Status").SetValue("Canceled");
                }
            }
        }
Exemplo n.º 3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.main);
            var textView = FindViewById <TextView> (Resource.Id.textView);

            // create an object
            var account = new Account("Xamarin", "Corporate");

            // create the serializer
            var gson = new GsonBuilder()
                       .SetPrettyPrinting()
                       .Create();

            // serialize the object into json
            var json = gson.ToJson(account);

            // deserialize the json into the object
            var clazz      = Java.Lang.Class.FromType(typeof(Account));
            var newAccount = (Account)gson.FromJson(json, clazz);

            textView.Text = string.Join(System.Environment.NewLine, new [] {
                json,
                "Name == 'Xamarin': " + (newAccount.Name == "Xamarin"),
                "Type == 'Corporate': " + (newAccount.Type == "Corporate")
            });
        }
Exemplo n.º 4
0
        //public static string EncodeToBase64(Bitmap image, Bitmap.CompressFormat compressFormat, int quality)
        //{
        //    System.IO.MemoryStream byteArrayOS = new System.IO.MemoryStream();
        //    image.Compress(compressFormat, quality, byteArrayOS);
        //    return Base64.encodeToString(byteArrayOS.toByteArray(), Base64.DEFAULT);
        //}

        //public static Bitmap decodeBase64(String input)
        //{
        //    byte[] decodedBytes = Base64.Deco(input, 0);
        //    return BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.length);
        //}
        public static T Cast <T>(DataSnapshot obj) where T : class
        {
            HashMap map     = obj.Value.JavaCast <HashMap>();
            Gson    gson    = new GsonBuilder().Create();
            string  jsonObj = gson.ToJson(map);

            return(JsonConvert.DeserializeObject <T>(jsonObj) as T);
        }
Exemplo n.º 5
0
 public void OnDataChange(DataSnapshot snapshot)
 {
     //"Data received for user orders");
     var gson = new GsonBuilder().SetPrettyPrinting().Create();
     var json = gson.ToJson(snapshot.Value); // Gson extention method obj -> string
     Formatted_Output("Data received for user order json ", json);
     User user = JsonConvert.DeserializeObject<User>(json); //Newtonsoft.Json extention method string -> object
     
    //now the user is a fully populated object with very little work
 }
        public void OnMapReady(MapboxMap mapboxMap)
        {
            this.mapboxMap     = mapboxMap;
            navigationMapRoute = new NavigationMapRoute(null, mapView, mapboxMap, "admin-3-4-boundaries-bg");
            Gson gson = new GsonBuilder().RegisterTypeAdapterFactory(DirectionsAdapterFactory.Create()).Create();
            var  json = loadJsonFromAsset(DIRECTIONS_RESPONSE);
            DirectionsResponse response = (DirectionsResponse)gson.FromJson(json, Class.FromType(typeof(DirectionsResponse)));

            navigationMapRoute.AddRoute(response.Routes()[0]);
            mapboxMap.SetOnMapLongClickListener(this);
            navigationMapRoute.SetOnRouteSelectionChangeListener(this);
        }
Exemplo n.º 7
0
            public void OnDataChange(DataSnapshot snapshot)
            {
                if (snapshot.Exists())
                {
                    Gson gson = new GsonBuilder().Create();

                    HashMap map = snapshot.Value.JavaCast <HashMap>();

                    string tripdata = gson.ToJson(map);

                    MessagingCenter.Send <object, string>(this, "tripin", tripdata);
                }
            }
Exemplo n.º 8
0
        void IChildEventListener.OnChildAdded(DataSnapshot snapshot, string previousChildName)
        {
            HashMap dataHashMap         = snapshot.Value.JavaCast <HashMap>();
            Gson    gson                = new GsonBuilder().Create();
            string  chatItemDaataString = gson.ToJson(dataHashMap);

            // Try to deserialize :
            try
            {
                T chatItems = JsonConvert.DeserializeObject <T>(chatItemDaataString);
                action("temp", chatItems);
            }
            catch
            {
            }
        }
Exemplo n.º 9
0
        public string SetChildValueByAutoId(string nodeKey, object obj, Action onSuccess = null, Action <string> onError = null)
        {
            DatabaseReference dr = FirebaseDatabase.Instance.GetReference(nodeKey);

            if (dr != null)
            {
                string objJsonString = JsonConvert.SerializeObject(obj);

                Gson             gson        = new GsonBuilder().SetPrettyPrinting().Create();
                HashMap          dataHashMap = new HashMap();
                Java.Lang.Object jsonObj     = gson.FromJson(objJsonString, dataHashMap.Class);
                dataHashMap = jsonObj.JavaCast <HashMap>();
                DatabaseReference newChildRef = dr.Push();
                newChildRef.SetValue(dataHashMap);
                return(newChildRef.Key);
            }

            return(null);
        }
Exemplo n.º 10
0
        public void UpdateDriverLocation(string key, object v)
        {
            DatabaseReference dr = FirebaseDatabase.Instance.GetReference("drivers");

            if (dr != null)
            {
                string objJsonString = JsonConvert.SerializeObject(v);

                Gson gson = new GsonBuilder().SetPrettyPrinting().Create();

                HashMap dataHashMap = new HashMap();

                Java.Lang.Object jsonObj = gson.FromJson(objJsonString, dataHashMap.Class);

                dataHashMap = jsonObj.JavaCast <HashMap>();

                dr.Child(key).Child("Location").SetValue(dataHashMap);
            }
        }
Exemplo n.º 11
0
        public async Task <string> StartTrip(string key, object trip)
        {
            DatabaseReference tripref = FirebaseDatabase.Instance.GetReference("trips");

            DatabaseReference driverref = FirebaseDatabase.Instance.GetReference("drivers");

            DatabaseReference reqref = FirebaseDatabase.Instance.GetReference("requests").Child(key);

            string uid = await new AFirebaseAuthClass().GetCurrentUser();

            var Key = tripref.Push().Key;

            // update request
            // With key
            if (tripref != null)
            {
                string objJsonString = JsonConvert.SerializeObject(trip);

                Gson gson = new GsonBuilder().SetPrettyPrinting().Create();

                HashMap dataHashMap = new HashMap();

                Java.Lang.Object jsonObj = gson.FromJson(objJsonString, dataHashMap.Class);

                dataHashMap = jsonObj.JavaCast <HashMap>();

                tripref.Child(Key).SetValue(dataHashMap);

                tripref.Child(Key).Child("Key").SetValue(Key);

                reqref.Child("Key").SetValue(Key);

                reqref.Child("Status").SetValue("Accepted");

                driverref.Child(uid).Child("Trip").SetValue(Key);

                return(Key);
            }
            // start trip
            return(null);
        }
Exemplo n.º 12
0
        public void SetBooking(string nodeKey, object obj, Action onSuccess = null, Action <string> onError = null)
        {
            DatabaseReference dr = FirebaseDatabase.Instance.GetReference(nodeKey);

            if (dr != null)
            {
                string objJsonString = JsonConvert.SerializeObject(obj);

                Gson gson = new GsonBuilder().SetPrettyPrinting().Create();

                HashMap dataHashMap = new HashMap();

                Java.Lang.Object jsonObj = gson.FromJson(objJsonString, dataHashMap.Class);

                dataHashMap = jsonObj.JavaCast <HashMap>();

                var key = dr.Push().Key;

                dr.Child(key).SetValue(dataHashMap);
                dr.Child(key).Child("Key").SetValue(key);
            }
        }
Exemplo n.º 13
0
        public void CreateProfile(string nodeKey, object obj, Action onSuccess = null, Action <string> onError = null)
        {
            DatabaseReference dr = FirebaseDatabase.Instance.GetReference(nodeKey);

            string uid = mAuth.CurrentUser.Uid;

            if (dr != null)
            {
                string objJsonString = JsonConvert.SerializeObject(obj);

                Gson gson = new GsonBuilder().SetPrettyPrinting().Create();

                HashMap dataHashMap = new HashMap();

                Java.Lang.Object jsonObj = gson.FromJson(objJsonString, dataHashMap.Class);

                dataHashMap = jsonObj.JavaCast <HashMap>();

                dr.Child(uid).SetValue(dataHashMap);
                dr.Child(uid).Child("Key").SetValue(uid);
            }
        }
Exemplo n.º 14
0
        void IValueEventListener.OnDataChange(DataSnapshot snapshot)
        {
            string chatItemsString = snapshot.Value.ToString();
            object chatItemsObject = snapshot.Value;

            HashMap javaObjChatItems    = snapshot.Value.JavaCast <HashMap>();
            Gson    gson                = new GsonBuilder().SetPrettyPrinting().Create();
            string  chatItemDaataString = gson.ToJson(javaObjChatItems);

            Dictionary <string, ChatItem> chatItems = JsonConvert.DeserializeObject <Dictionary <string, ChatItem> >(chatItemDaataString);
            //// create the serializer
            //var gson = new GsonBuilder()
            //	.SetPrettyPrinting()
            //	.Create();
            //String mapAsJson = JsonConvert.SerializeObject(javaObjChatItems);


            //Dictionary<string, ChatItem> chatItems = ObjectTypeHelper.Cast<Dictionary<string, ChatItem>>(snapshot.Value);
            //Dictionary<string, ChatItem> chatItems = snapshot.Value as Dictionary<string, ChatItem>;
            //snapshot.

            //HashMap javaObjChatItems = snapshot.Value.JavaCast<HashMap>();
            //String mapAsJson = new ObjectMapper().writeValueAsString(javaObjChatItems);
            //ChatItem chatItem = ObjectTypeHelper.Cast<ChatItem>(javaObjChatItems.Get("item1"));
            //Dictionary<string, ChatItem> chatItems = snapshot.GetValue(ChatItem.);
            //JSON.Stringify(chatItemsObject);
            //Dictionary<string, ChatItem> chatItems = JsonConvert.DeserializeObject<Dictionary<string, ChatItem>>(chatItemDaataString);
            //Dictionary<string, ChatItem> chatItems = snapshot.GetValue(type of Dictionary);//JsonConvert.DeserializeObject<Dictionary<string, ChatItem>>(chatItemsString);
            //GenericTypeIndicator t = new GenericTypeIndicator() { };
            //NSDictionary chatItemData = snapshot.GetValue<NSDictionary>();
            //string test = snapshot.Key;
            //NSError error = null;
            //string chatItemDaataString = NSJsonSerialization.Serialize(chatItemData, NSJsonWritingOptions.PrettyPrinted, out error).ToString();

            //ChatItem chatItem = JsonConvert.DeserializeObject<ChatItem>(chatItemDaataString);
            //BigSlickChatPage.messages.Add(chatItems.First().Value);
            //throw new NotImplementedException();
        }
Exemplo n.º 15
0
 void IValueEventListener.OnDataChange(DataSnapshot snapshot)
 {
     if (snapshot.Exists() && snapshot.HasChildren)
     {
         HashMap dataHashMap = snapshot.Value.JavaCast <HashMap>();
         Gson    gson        = new GsonBuilder().Create();
         string  data        = gson.ToJson(dataHashMap);
         // Try to deserialize :
         try
         {
             T chatItems = JsonConvert.DeserializeObject <T>(data);
             action(chatItems);
         }
         catch
         {
         }
     }
     else
     {
         T item = default(T);
         action(item);
     }
 }
Exemplo n.º 16
0
        public void SubmitFeedback(object feedback)
        {
            DatabaseReference dr = FirebaseDatabase.Instance.GetReference("feedbacks");

            if (dr != null)
            {
                string objJsonString = JsonConvert.SerializeObject(feedback);

                Gson gson = new GsonBuilder().SetPrettyPrinting().Create();

                HashMap dataHashMap = new HashMap();

                Java.Lang.Object jsonObj = gson.FromJson(objJsonString, dataHashMap.Class);

                dataHashMap = jsonObj.JavaCast <HashMap>();

                var Key = dr.Push().Key;

                var feedbackref = dr.Child(Key);

                feedbackref.SetValue(dataHashMap);
            }
        }