Esempio n. 1
0
		public static Recipe FromJson(Context context, JSONObject json) {
			var recipe = new Recipe ();
			try 
			{
				recipe.TitleText = json.GetString(Constants.RecipeFieldTitle);
				recipe.SummaryText = json.GetString(Constants.RecipeFieldSummary);
				if (json.Has(Constants.RecipeFieldImage)) {
					recipe.RecipeImage = json.GetString(Constants.RecipeFieldImage);
				}
				JSONArray ingredients = json.GetJSONArray(Constants.RecipeFieldIngredients);
				recipe.IngredientsText = "";
				for (int i = 0; i < ingredients.Length(); i++)
				{
					recipe.IngredientsText += " - " + ingredients.GetJSONObject(i).GetString(Constants.RecipeFieldText) + "\n";
				}

				JSONArray steps = json.GetJSONArray(Constants.RecipeFieldSteps);
				for (int i = 0; i < steps.Length(); i++)
				{
					var step = steps.GetJSONObject(i);
					var recipeStep = new RecipeStep();
					recipeStep.StepText = step.GetString(Constants.RecipeFieldText);
					if (step.Has(Constants.RecipeFieldName)) {
						recipeStep.StepImage = step.GetString(Constants.RecipeFieldImage);
					}
					recipe.RecipeSteps.Add(recipeStep);
				}
			}
			catch (Exception ex) {
				Log.Error (Tag, "Error loading recipe: " + ex);
				return null;
			}
			return recipe;
		}
        public void doOnMessageReceive(String message)
        {
            string me = GetString (Resource.String.on_message);
            me = me.Replace("%s", message);
            mGeneralStatus.Text = me;

            //			mGeneralStatus.SetText(GetString(Resource.String.on_message, message));

            // Parse custom JSON data string.
            // You can set background color with custom JSON data in the following format: { "r" : "10", "g" : "200", "b" : "100" }
            // Or open specific screen of the app with custom page ID (set ID in the { "id" : "2" } format)

            try
            {

                JSONObject messageJson = new JSONObject(message);
                JSONObject customJson = new JSONObject(messageJson.GetString("u"));

                if (customJson.Has("r") && customJson.Has("g") && customJson.Has("b"))
                {
                    int r = customJson.GetInt("r");
                    int g = customJson.GetInt("g");
                    int b = customJson.GetInt("b");
                    Window.DecorView.FindViewById<View>(Android.Resource.Id.Content).SetBackgroundColor(Android.Graphics.Color.Rgb(r, g, b));
                }

                if (customJson.Has("id"))
                {
                    Intent intent = new Intent(this, typeof(SecondActivity));
                    intent.PutExtra(PushManager.PushReceiveEvent, messageJson.ToString());
                    StartActivity(intent);
                }
            }
            catch (JSONException e) {
                e.PrintStackTrace ();
            }
        }