Exemple #1
0
        public static BasicChooseTopicsFragment NewInstance()
        {
            var fragment = new BasicChooseTopicsFragment {
                Arguments = new Bundle()
            };

            return(fragment);
        }
Exemple #2
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            base.OnCreateView(inflater, container, savedInstanceState);
            View view = inflater.Inflate(Resource.Layout.basic_fragment_ask, null);

            Activity.Title = "Post New Task";


            titleText = view.FindViewById <EditText>(Resource.Id.ask_edit_title);
            bodyText  = view.FindViewById <EditText>(Resource.Id.ask_edit_body);
            topics    = view.FindViewById <TextView>(Resource.Id.topics);

            topics.Click += (sender, e) =>
            {
                FragmentManager.BeginTransaction().Replace(Resource.Id.content_frame, BasicChooseTopicsFragment.NewInstance())
                .AddToBackStack(null).Commit();
            };

            topics.Text = ViewModel.GetChoosedTopicsString();

            //// get the resources from the layout
            //btnRec = view.FindViewById<Button>(Resource.Id.btn_use_speech_to_text);

            // check to see if we can actually record - if we can, assign the event to the button
            //string rec = Android.Content.PM.PackageManager.FeatureMicrophone;
            //if (rec != "android.hardware.microphone")
            //{
            //    // no microphone, no recording. Disable the button and output an alert
            //    var alert = new AlertDialog.Builder(titleText.Context);
            //    alert.SetTitle("You don't seem to have a microphone to record with");
            //    alert.SetPositiveButton("OK", (sender, e) =>
            //    {
            //        titleText.Text = "No microphone present";
            //        titleText.Enabled = false;
            //        return;
            //    });

            //    alert.Show();
            //}
            //else
            titleText.LongClick += delegate
            {
                if (titleText.IsFocused == false)
                {
                    return;
                }
                // create the intent and start the activity
                var voiceIntent = new Intent(RecognizerIntent.ActionRecognizeSpeech);
                voiceIntent.PutExtra(RecognizerIntent.ExtraLanguageModel, RecognizerIntent.LanguageModelFreeForm);

                // put a message on the modal dialog
                voiceIntent.PutExtra(RecognizerIntent.ExtraPrompt, "Speak now");

                // if there is more then 1.5s of silence, consider the speech over
                voiceIntent.PutExtra(RecognizerIntent.ExtraSpeechInputCompleteSilenceLengthMillis, 1500);
                voiceIntent.PutExtra(RecognizerIntent.ExtraSpeechInputPossiblyCompleteSilenceLengthMillis, 1500);
                voiceIntent.PutExtra(RecognizerIntent.ExtraSpeechInputMinimumLengthMillis, 15000);
                voiceIntent.PutExtra(RecognizerIntent.ExtraMaxResults, 1);

                // you can specify other languages recognised here, for example
                // voiceIntent.PutExtra(RecognizerIntent.ExtraLanguage, Java.Util.Locale.German);
                // if you wish it to recognise the default Locale language and German
                // if you do use another locale, regional dialects may not be recognised very well

                voiceIntent.PutExtra(RecognizerIntent.ExtraLanguage, Java.Util.Locale.Default);
                try
                {
                    StartActivityForResult(voiceIntent, VOICE);
                }
                catch (ActivityNotFoundException)
                {
                    Toast.MakeText(Context, "Sorry! Your device doesn\'t support speech input", ToastLength.Short).Show();
                }
            };

            return(view);
        }