예제 #1
0
        protected override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            sounds = new List <MicSound>();
            var tempSound1 = new MicSound();

            tempSound1.sound_name     = "...";
            tempSound1.sound_settings = SoundsManager.NewSoundSettings();
            //tempSound1.settings.Add("Push", true.ToString());
            //tempSound1.settings.Add("ShowMessage", false.ToString());
            //tempSound1.settings.Add("Vibrate", true.ToString());
            //sounds.Add(tempSound1);

            SetContentView(Resource.Layout.page_sounds);
            var toolbar = FindViewById <V7Toolbar>(Resource.Id.toolbar);

            SetSupportActionBar(toolbar);
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);

            mRegistrationBroadcastReceiver          = new Shared.BroadcastReceiver();
            mRegistrationBroadcastReceiver.Receive += (sender, e) =>
            {
                //progressDialog.Dismiss();5
                var result = e.Intent.GetStringExtra("reply_error");
                if (result == Shared.ServerResponsecode.STARTED_RECORDING.ToString())
                {
                    if (progressDialog != null)
                    {
                        progressDialog.Dismiss();
                    }
                    //if (awaitingResponse == ExpectedResponse.NowRecording)
                    {
                        //progressDialog = Android.App.ProgressDialog.Show(this, "RECORDING...", "Play your sound...", true);
                        Acr.UserDialogs.UserDialogs.Instance.Loading("RECORDING, Play your sound!");
                        awaitingResponse = ExpectedResponse.DoneRecording;
                    }
                }
                else if (result == Shared.ServerResponsecode.DONE_RECORDING.ToString())
                {
                    if (progressDialog != null)
                    {
                        progressDialog.Dismiss();
                    }
                    //if (awaitingResponse == ExpectedResponse.DoneRecording)
                    {
                        var progress = Acr.UserDialogs.UserDialogs.Instance.Progress("");
                        progress.Hide();
                        Acr.UserDialogs.UserDialogs.Instance.HideLoading();
                        Acr.UserDialogs.UserDialogs.Instance.ShowSuccess("Recording complete.");

                        GetSoundList();
                    }
                }
            };

            listView            = FindViewById <ListView>(Resource.Id.soundsListView);
            listView.ItemClick += OnListItemClick;

            adapter          = new SoundAdapter(this, sounds);
            listView.Adapter = adapter;

            LocalBroadcastManager.GetInstance(this).RegisterReceiver(mRegistrationBroadcastReceiver,
                                                                     new IntentFilter("reply_error"));

            //wavioId = savedInstanceState.GetString("id", "");

            var prefs = PreferenceManager.GetDefaultSharedPreferences(Application.Context);

            wavioId = prefs.GetString("edit_mic_id", "");

            GetSoundList();
        }
예제 #2
0
        private void AddNewSoundRequest(string soundName)
        {
            Acr.UserDialogs.UserDialogs.Instance.Loading("Sending request...");

            string hwid                     = Android.OS.Build.Serial;
            var    SharedSettings           = new Dictionary <String, String>();
            var    prefs                    = PreferenceManager.GetDefaultSharedPreferences(Application.Context);
            ISharedPreferencesEditor editor = prefs.Edit();
            String gcmID                    = prefs.GetString("GCMID", "");

            var newSound = new MicSound();

            newSound.sound_name     = soundName;
            newSound.sound_image    = "http://jmprog.com/hzinnovations/icons/pulse2.png";
            newSound.sound_settings = SoundsManager.NewSoundSettings();

            try
            {
                if (string.IsNullOrEmpty(wavioId))
                {
                    if (progressDialog != null)
                    {
                        progressDialog.Dismiss();
                    }
                    Acr.UserDialogs.UserDialogs.Instance.ErrorToast("Error: Missing ID");
                    return;
                }


                var client     = new RestClient(Shared.SERVERURL);
                var request    = new RestRequest("resource/{id}", Method.POST);
                var parameters = new Dictionary <string, string>();

                parameters.Add(Shared.ParamType.REQUEST_CODE, Shared.RequestCode.RECORD_NEW_SOUND.ToString());
                parameters.Add(Shared.ParamType.SOUND_INFO, JsonConvert.SerializeObject(newSound));

                parameters.Add(Shared.ParamType.WAVIO_ID, wavioId);
                parameters.Add(Shared.ParamType.GCM_ID, gcmID);
                parameters.Add(Shared.ParamType.HWID, hwid);
                string requestJson = JsonConvert.SerializeObject(parameters);
                request.AddParameter(Shared.ParamType.REQUEST, requestJson);

                Console.WriteLine("Waiting for response");


                client.ExecuteAsync(request, response => {
                    ServerResponse serverResponse = JsonConvert.DeserializeObject <ServerResponse>(response.Content);

                    if (serverResponse == null)
                    {
                        //Acr.UserDialogs.UserDialogs.Instance.ShowError("Unknown error!");
                        return;
                    }


                    if (serverResponse.error == Shared.ServerResponsecode.OK)
                    {
                        Acr.UserDialogs.UserDialogs.Instance.Loading("Initializing mic...", RecordCanceled);

                        awaitingResponse = ExpectedResponse.NowRecording;
                    }
                    else if (serverResponse.error == Shared.ServerResponsecode.DATABASE_ERROR)
                    {
                        Acr.UserDialogs.UserDialogs.Instance.ShowError("Server error!");
                    }
                    else
                    {
                        if (serverResponse.request != Shared.RequestCode.RECORD_NEW_SOUND)
                        {
                            Acr.UserDialogs.UserDialogs.Instance.ShowError("Request type mismatch!");
                            return;
                        }
                        Acr.UserDialogs.UserDialogs.Instance.ShowError("Unknown error!");
                    }
                    return;
                });
            }
            catch (WebException ex)
            {
                string _exception = ex.ToString();
                if (progressDialog != null)
                {
                    progressDialog.Dismiss();
                }
                Acr.UserDialogs.UserDialogs.Instance.ShowError("Network error!");
                Console.WriteLine("--->" + _exception);
            }
        }