示例#1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.Demo05Spinner);

            var adapter = ArrayAdapter.CreateFromResource(this, Resource.Array.CourseItems, Android.Resource.Layout.SimpleSpinnerItem);

            adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);

            spinner               = FindViewById <Spinner>(Resource.Id.spinner1);
            spinner.Adapter       = adapter;
            spinner.ItemSelected += Spinner_ItemSelected;

            var btn = FindViewById <Button>(Resource.Id.buttonOK);

            btn.Click += delegate
            {
                string s = spinner.SelectedItem.ToString();
                Toast.MakeText(this, s, ToastLength.Long).Show();
            };

            CActivityManager.GetInstence().AddActivity(this);
        }
示例#2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.Demo07PopupMenu);

            Button btn = FindViewById <Button>(Resource.Id.popupButton);

            btn.Click += (s, arg) =>
            {
                PopupMenu menu = new PopupMenu(this, btn);
                menu.Inflate(Resource.Menu.Demo07PopupMenu);
                menu.MenuItemClick += (sender, args) =>
                {
                    string str = string.Format("你选择了:{0}", args.Item);
                    Toast.MakeText(this, str, ToastLength.Short).Show();
                };
                menu.DismissEvent += (sender, args) =>
                {
                    // 菜单消失后可在此事件中做一些后续处理
                    Toast.MakeText(this, "弹出菜单消失了", ToastLength.Short).Show();
                };
                menu.Show();
            };

            CActivityManager.GetInstence().AddActivity(this);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.Demo10Toast);

            var btnDefault = FindViewById <Button>(Resource.Id.btnDefault);

            btnDefault.Click += Button_Click;

            var btnPhoto = FindViewById <Button>(Resource.Id.btnPhoto);

            btnPhoto.Click += Button_Click;

            var btnPosition = FindViewById <Button>(Resource.Id.btnPosition);

            btnPosition.Click += Button_Click;

            var btnCustom = FindViewById <Button>(Resource.Id.btnCustom);

            btnCustom.Click += Button_Click;

            var btnThread = FindViewById <Button>(Resource.Id.btnThread);

            btnThread.Click += Button_Click;

            CActivityManager.GetInstence().AddActivity(this);
        }
        protected override void OnDestroy()
        {
            base.OnDestroy();

            bIsWebSocketHandlerOn = false;
            if (wsClient != null)
            {
                wsClient.CloseAsync(System.Net.WebSockets.WebSocketCloseStatus.NormalClosure, "AdSubApp closed", System.Threading.CancellationToken.None).Wait(1000);
                wsClient.Dispose();
                wsClient = null;
            }
            if (WebSocketThread != null)
            {
                WebSocketThread.Dispose();
                WebSocketThread = null;
            }

            bIsHeartBeatThreadOn = false;
            if (HeartBeatThread != null)
            {
                HeartBeatThread.Dispose();
                HeartBeatThread = null;
            }

            bIsProgramControlThreadOn = false;
            bIsProgramLoop            = false;
            if (ProgramControlThread != null)
            {
                ProgramControlThread.Dispose();
                ProgramControlThread = null;
            }

            CActivityManager.GetInstence().FinishAllActivity();
            Settings.RuntimeLog.Info("OnDestroy");
        }
示例#5
0
        protected override void OnDestroy()
        {
            base.OnDestroy();

            StopVideoPlayer();

            if (mediaPlayer != null)
            {
                mediaPlayer.SetDisplay(null);
                mediaPlayer.Release();
                mediaPlayer.Dispose();
                mediaPlayer = null;
            }

            if (holder != null)
            {
                holder.Dispose();
                holder = null;
            }

            if (videoView != null)
            {
                videoView.Holder.Dispose();
                videoView.DestroyDrawingCache();
                videoView.Dispose();
                videoView = null;
            }

            CActivityManager.GetInstence().FinishSingleActivity(this);
            Settings.semVideoCompleted.Release();
        }
示例#6
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.Demo09SeekBar);

            seekBar1  = FindViewById <SeekBar>(Resource.Id.seekBar1);
            textView1 = FindViewById <TextView>(Resource.Id.textView1);

            seekBar2  = FindViewById <SeekBar>(Resource.Id.seekBar2);
            textView2 = FindViewById <TextView>(Resource.Id.textView2);
            textView3 = FindViewById <TextView>(Resource.Id.textView3);

            // 用法1:(常用)
            seekBar1.ProgressChanged += (s, e) =>
            {
                if (e.FromUser)
                {
                    textView1.Text = string.Format("seekBar1 值为 {0}", e.Progress);
                }
            };

            // 用法2:(用接口实现)
            seekBar2.SetOnSeekBarChangeListener(this);

            CActivityManager.GetInstence().AddActivity(this);
        }
示例#7
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.Demo01EditText);

            var txtResult = FindViewById <TextView>(Resource.Id.txtResult);

            txtResult.SetTextColor(Color.Red);
            txtResult.Enabled = false;

            var txt1 = FindViewById <EditText>(Resource.Id.editText1);

            txt1.TextChanged += (s, e) =>
            {
                txtResult.Text = "输入的内容为:" + txt1.Text;
            };

            var txt2 = FindViewById <EditText>(Resource.Id.editText2);

            txt2.TextChanged += (s, e) =>
            {
                txtResult.Text = "输入的内容为:" + txt2.Text;
            };

            CActivityManager.GetInstence().AddActivity(this);
        }
        protected override void OnDestroy()
        {
            base.OnDestroy();

            ClearAnimation();

            if (bm != null)
            {
                if (!bm.IsRecycled)
                {
                    bm.Recycle();
                }
                bm.Dispose();
                bm = null;
            }

            if (imageView != null)
            {
                imageView.SetImageBitmap(null);
                imageView.DestroyDrawingCache();
                imageView.Drawable.Dispose();
                imageView.Dispose();
                imageView = null;
            }

            CActivityManager.GetInstence().FinishSingleActivity(this);
        }
示例#9
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.Demo02Login);

            Button btn = FindViewById <Button>(Resource.Id.buttonLogin);

            btn.Click += Btn_Click;  // 技巧:按+=后,连续按两次<Tab>键

            CActivityManager.GetInstence().AddActivity(this);
        }
        protected override void OnDestroy()
        {
            base.OnDestroy();

            bIsHeartBeatThreadOn = false;
            if (HeartBeatThread != null)
            {
                HeartBeatThread.Dispose();
                HeartBeatThread = null;
            }

            CActivityManager.GetInstence().FinishAllActivity();
        }
示例#11
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // 隐藏标题栏
            this.RequestWindowFeature(WindowFeatures.NoTitle);
            // 隐藏状态栏
            this.Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);
            // 将背景设置为空
            this.Window.SetBackgroundDrawable(null);

            // Create your application here
            SetContentView(Resource.Layout.Demo2002VideoView);

            if (videoView == null)
            {
                videoView = FindViewById <VideoView>(Resource.Id.videoView);
            }

            if (holder == null)
            {
                holder = videoView.Holder;
            }
            holder.AddCallback(this);

            if (mediaPlayer == null)
            {
                mediaPlayer = new MediaPlayer();
            }
            mediaPlayer.Prepared   += MediaPlayer_Prepared;
            mediaPlayer.Completion += MediaPlayer_Completion;

            string uri = Intent.Extras.GetString("uri") ?? "";

            if (string.IsNullOrEmpty(uri))
            {
                CActivityManager.GetInstence().FinishSingleActivity(this);
            }
            else
            {
                bool bIsLoop = false;
                if (!string.IsNullOrEmpty(Intent.Extras.GetString("bIsLoop")) && Intent.Extras.GetString("bIsLoop") == "true")
                {
                    bIsLoop = true;
                }
                StartVideoPlayer(uri, bIsLoop);
            }

            CActivityManager.GetInstence().AddActivity(this);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // 隐藏标题栏
            this.RequestWindowFeature(WindowFeatures.NoTitle);
            // 隐藏状态栏
            this.Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);
            // 将背景设置为空
            this.Window.SetBackgroundDrawable(null);

            // Create your application here
            SetContentView(Resource.Layout.Demo2003ImageView);

            if (imageView == null)
            {
                imageView = FindViewById <ImageView>(Resource.Id.imageView1);
            }
            imageView.SetScaleType(ImageView.ScaleType.FitXy);

            string uri = Intent.Extras.GetString("uri") ?? "";

            if (string.IsNullOrEmpty(uri))
            {
                CActivityManager.GetInstence().FinishSingleActivity(this);
            }
            else
            {
                try
                {
                    //using (var tmp = Android.Net.Uri.Parse("file://" + uri))
                    //{
                    //    imageView.SetImageURI(tmp);
                    //}

                    bm = BitmapFactory.DecodeFile(uri);
                    imageView.SetImageBitmap(bm);
                }
                catch (Exception e)
                {
                    System.Console.WriteLine("imageView Exception: " + e.Message);
                }
            }

            CActivityManager.GetInstence().AddActivity(this);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.Demo04CheckBoxRadioButton);

            red   = FindViewById <CheckBox>(Resource.Id.checkBoxRed);
            green = FindViewById <CheckBox>(Resource.Id.checkBoxGreen);
            nan   = FindViewById <RadioButton>(Resource.Id.radioButtonMale);
            nv    = FindViewById <RadioButton>(Resource.Id.radioButtonFamale);

            var button = FindViewById <Button>(Resource.Id.btnOK);

            button.Click += Button_Click;

            CActivityManager.GetInstence().AddActivity(this);
        }
示例#14
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.Demo08Gallery);

            var g = FindViewById <Gallery>(Resource.Id.gallery);

            g.Adapter = new ImageAdapter(this)
            {
                CurrentWidth  = 550,
                CurrentHeight = 550
            };
            g.ItemClick += Gallery_ItemClick;

            CActivityManager.GetInstence().AddActivity(this);
        }
示例#15
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.Demo03MultiResolution);

            ShowPhoto(photo_index);

            Button nextButton = FindViewById <Button>(Resource.Id.next_button);

            nextButton.Click += delegate
            {
                photo_index = (photo_index + 1) % photo_ids.Count;
                ShowPhoto(photo_index);
            };

            CActivityManager.GetInstence().AddActivity(this);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.Demo06SwitchAndRatingBar);

            Button button = FindViewById <Button>(Resource.Id.button);

            button.Click += delegate
            {
                Toast.MakeText(this, "Beep Boop", ToastLength.Short).Show();
            };

            var editText = FindViewById <EditText>(Resource.Id.edittext);

            //---------------------------------------------------------
            //技巧:按+=后,连续按两次<Tab>键,就会自动生成事件处理程序
            //---------------------------------------------------------
            editText.KeyPress += EditText_KeyPress;

            var checkbox = FindViewById <CheckBox>(Resource.Id.checkbox);

            checkbox.Click += delegate
            {
                if (checkbox.Checked)
                {
                    Toast.MakeText(this, "Selected", ToastLength.Short).Show();
                }
                else
                {
                    Toast.MakeText(this, "Not selected", ToastLength.Short).Show();
                }
            };

            var radioRed  = FindViewById <RadioButton>(Resource.Id.radio_red);
            var radioBlue = FindViewById <RadioButton>(Resource.Id.radio_blue);

            radioRed.Click  += Radio_Click;
            radioBlue.Click += Radio_Click;

            Switch toggleButton = FindViewById <Switch>(Resource.Id.togglebutton);

            toggleButton.Click += (o, e) =>
            {
                if (toggleButton.Checked)
                {
                    Toast.MakeText(this, "Checked", ToastLength.Short).Show();
                }
                else
                {
                    Toast.MakeText(this, "Not checked", ToastLength.Short).Show();
                }
            };

            RatingBar ratingbar = FindViewById <RatingBar>(Resource.Id.ratingbar);

            ratingbar.RatingBarChange += (o, e) =>
            {
                Toast.MakeText(this, "New Rating: " + ratingbar.Rating.ToString(), ToastLength.Short).Show();
            };

            CActivityManager.GetInstence().AddActivity(this);
        }
示例#17
0
 private void MediaPlayer_Completion(object sender, EventArgs e)
 {
     Console.WriteLine("MediaPlayer_Completion");
     CActivityManager.GetInstence().FinishSingleActivity(this);
 }
示例#18
0
 protected override void OnRestart()
 {
     base.OnRestart();
     CActivityManager.GetInstence().FinishSingleActivity(this);
 }
        /// <summary>
        /// 节目控制
        /// </summary>
        public void ProgramControl()
        {
            // 读取配置文件
            JSONObject jsonConfig = ReadConfig();

            if (jsonConfig != null)
            {
                // 正在载入节目
                RunOnUiThread(() =>
                {
                    Toast.MakeText(this, "正在载入节目...", ToastLength.Long).Show();
                });
                Settings.RuntimeLog.Info("正在载入节目...");
                bIsProgramLoop = true;
            }
            else
            {
                return;
            }

            // 节目循环
            using (JSONObject program = jsonConfig.OptJSONObject("program"))
                using (JSONArray resources = program.OptJSONArray("resources"))
                {
                    int i = -1, nLength = resources.Length();
                    while (bIsProgramLoop)
                    {
                        i = (i + 1) % nLength;                                                                // 资源循环
                        CActivityManager.GetInstence().FinishSingleActivityByType(typeof(VideoViewActivity)); // 关闭视频播放
                        CActivityManager.GetInstence().FinishSingleActivityByType(typeof(ImageViewActivity)); // 关闭图片播放
                        if (!bIsProgramLoop)
                        {
                            // 重新载入节目
                            RunOnUiThread(() =>
                            {
                                Toast.MakeText(this, "重新载入节目...", ToastLength.Long).Show();
                            });
                            Settings.RuntimeLog.Info("重新载入节目...");
                            break;
                        }
                        System.Threading.Thread.Sleep(50);
                        string name, type, md5, url, duration;
                        using (JSONObject resource = resources.GetJSONObject(i))
                        {
                            name     = resource.OptString("name");
                            type     = resource.OptString("type");
                            md5      = resource.OptString("md5");
                            url      = resource.OptString("url");
                            duration = resource.OptString("duration");
                        }
                        if (type == "video")
                        {
                            // 播放视频
                            RunOnUiThread(() =>
                            {
                                using (Intent intentVideo = new Intent(this, typeof(VideoViewActivity)))
                                {
                                    intentVideo.PutExtra("uri", Settings.AppPath + "/" + type + "/" + name);
                                    StartActivity(intentVideo);
                                }
                            });
                            Settings.semVideoCompleted.WaitOne(); // 等待视频结束
                        }
                        else if (type == "image")
                        {
                            // 播放图片
                            RunOnUiThread(() =>
                            {
                                using (Intent intentImage = new Intent(this, typeof(SrcActivity.ImageViewActivity)))
                                {
                                    intentImage.PutExtra("uri", Settings.AppPath + "/" + type + "/" + name);
                                    StartActivity(intentImage);
                                }
                            });

                            int nDuration = int.Parse(duration) + 1; // 图片播放时间
                            System.Threading.Thread.Sleep(nDuration * 1000);
                        }
                        else
                        {
                            // other type
                        }
                    }
                }

            if (jsonConfig != null)
            {
                jsonConfig.Dispose();
                jsonConfig = null;
            }
        }